Android Question [Solved] How to escape a string with the ( "$ ) characters within?

asales

Expert
Licensed User
Longtime User
I have this string: 6%>$#2"$6;2$0:6>;y48:

But If I try to make this:
B4X:
Dim s As String = "6%>$#2"$6;2$0:6>;y48:"

I get this error message in the IDE: The input string was not in the correct format.

It is because the apostrophe, but has the $ caracter after it and don't work if I make this:
B4X:
Dim s As String = $"6%>$#2"$6;2$0:6>;y48:"$

How can I fix this?

Thanks in advance for any tip.
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
The $ character is used in the literal string for entering a variable. So make a string with the $ character and refer to it like this:
Use of $ character in string:
    Dim str As String = "$"
    Dim s As String = $"6%>${str}#2"${str}6;2${str}0:6>;y48:"$
    Log(s)
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Here is another weird way of doing it and it works:
B4X:
Dim str As String=$"6%>$#2" $6;2$0:6>;y48:"$
str=str.Replace(" ","")
Log(str)   'displays: 6%>$#2"$6;2$0:6>;y48:
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
he $ character is used in the literal string for entering a variable
Not 100% accurate. The problem is with "$, which is the smart string terminator sequence. A $ alone will not need to be escaped.

Two more options:
B4X:
Dim s As String = $"6%>$#2"${"$"}6;2$0:6>;y48:"$ 'add the $ with a placeholder.
Dim s As String = "6%>$#2""$6;2$0:6>;y48:" 'double quotes
 
Upvote 0
Top