Pflichtfeld Active Member Licensed User Jun 28, 2020 #1 Is there as string-function that works like the localizeParams-Example: B4X: Copy MyString = anyfunction("Hello {1}, my name is {2}", Array as string("guys","Thomas")) or in VB.NET: B4X: Copy 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)
Is there as string-function that works like the localizeParams-Example: B4X: Copy MyString = anyfunction("Hello {1}, my name is {2}", Array as string("guys","Thomas")) or in VB.NET: B4X: Copy 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)
E emexes Expert Licensed User Longtime User Jun 28, 2020 #2 Code: Copy Dim name As String = "Hello {0}, my name is {1}".Replace("{0}", "guys").Replace("{1}", "Thomas") might get you where you want to go. Upvote 0
Code: Copy Dim name As String = "Hello {0}, my name is {1}".Replace("{0}", "guys").Replace("{1}", "Thomas") might get you where you want to go.
Pflichtfeld Active Member Licensed User Jun 28, 2020 #3 Thanks, emexes, that is a workaround. Upvote 0
E emexes Expert Licensed User Longtime User Jun 28, 2020 #4 You could use more meaningful placeholder names too, like: Code: Copy Dim Greeting As String = "Hello {group}, my name is {me}" Log( Greeting.Replace("{group}", "guys").Replace("{me}", "Thomas") ) Upvote 0
You could use more meaningful placeholder names too, like: Code: Copy Dim Greeting As String = "Hello {group}, my name is {me}" Log( Greeting.Replace("{group}", "guys").Replace("{me}", "Thomas") )
JohnC Expert Licensed User Longtime User Jun 28, 2020 #5 I can't think of one off the top of my head, but could do something like this: B4X: Copy MyString = "Hello {1}, my name is {2}" Mystring.Replace("{1}", "guys") Mystring.Replace("{2}", "Thomas") Upvote 0
I can't think of one off the top of my head, but could do something like this: B4X: Copy MyString = "Hello {1}, my name is {2}" Mystring.Replace("{1}", "guys") Mystring.Replace("{2}", "Thomas")
agraham Expert Licensed User Longtime User Jun 28, 2020 #6 [B4X] Smart String Literal The "smart string" literal is a more powerful version of the standard string literal. It has three advantages: Supports multi-line strings. No need to escape quotes. Supports string interpolation. The smart string literal starts with $" and ends with "$. Examples: Dim s As String = $"Hello... www.b4x.com Upvote 0
[B4X] Smart String Literal The "smart string" literal is a more powerful version of the standard string literal. It has three advantages: Supports multi-line strings. No need to escape quotes. Supports string interpolation. The smart string literal starts with $" and ends with "$. Examples: Dim s As String = $"Hello... www.b4x.com
Pflichtfeld Active Member Licensed User Jun 28, 2020 #7 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: Copy 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
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: Copy 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.
Erel B4X founder Staff member Licensed User Longtime User Jun 29, 2020 #8 You can use WebUtils.ReplaceMap: https://www.b4x.com/android/forum/threads/webapp-mini-template-engine.40182/#content Upvote 0
You can use WebUtils.ReplaceMap: https://www.b4x.com/android/forum/threads/webapp-mini-template-engine.40182/#content
aeric Expert Licensed User Longtime User Jun 29, 2020 #10 Erel said: You can use WebUtils.ReplaceMap: https://www.b4x.com/android/forum/threads/webapp-mini-template-engine.40182/#content Click to expand... Thanks. I am going to use this too. Upvote 0
Erel said: You can use WebUtils.ReplaceMap: https://www.b4x.com/android/forum/threads/webapp-mini-template-engine.40182/#content Click to expand... Thanks. I am going to use this too.