Android Question [Solved] Placeholder in strings?

Pflichtfeld

Active Member
Licensed User
Is there as string-function that works like the localizeParams-Example:
B4X:
MyString = anyfunction("Hello {1}, my name is {2}", Array as string("guys","Thomas"))
or in VB.NET:
B4X:
Dim name As String = String.Format("Hello {0}, my name is {1}", "guys", "Thomas")
which returns: "Hello guys, my name is Thomas"
(could not adapt smart string literal to my issue)
 

emexes

Expert
Licensed User
You could use more meaningful placeholder names too, like:
B4X:
Dim Greeting As String = "Hello {group}, my name is {me}"
Log( Greeting.Replace("{group}", "guys").Replace("{me}", "Thomas") )
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I can't think of one off the top of my head, but could do something like this:
B4X:
MyString = "Hello {1}, my name is {2}"

Mystring.Replace("{1}", "guys")
Mystring.Replace("{2}", "Thomas")
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
 
Upvote 0

Pflichtfeld

Active Member
Licensed User
Thanks agraham, as I wrote: (could not adapt smart string literal to my issue)
"You can put any code you like inside the placeholders.
B4X:
Dim x = 1, y = 2, z = 4 As Int
Log($"x = ${x}, y = ${y}, z = ${Sin(z)}"$) 'x = 1, y = 2, z = -0.7568024953079282
This is a compile time feature. You cannot load the strings from a file for example. "
That is what I wanna do, load the string from a file and insert the placeholder later.
 
Upvote 0
Top