Android Tutorial [B4X] Smart String Literal

DonManfred

Expert
Licensed User
Longtime User
B4X:
    Dim dstart As Long = DateTime.DateTimeParse("01.5.2015","00:00")
    log(DateTime.Date(dstart))
will log the date.... To use this in the literal you can use it like this
B4X:
Log($"The date is ${DateTime.Date(dstart)}"$)

this can be done in you
INITIAL_TEXT = $"html code..."$
too
 

Ed Brown

Active Member
Licensed User
Longtime User
Man! I wish I had seen this post for my last project! Smart Strings would have been a very handy feature.

Question: Are there any rules to Smart Strings in relation to obfuscation in Process_Globals? ie. Does obfuscation still work and do the same rules apply?
 

stari

Active Member
Licensed User
Longtime User
hi
i wish to send string:
{
"$token": "36ada5b10da39a1347559321baf13063",
}
but i can't include $.
Any seuggestion ?
 

stari

Active Member
Licensed User
Longtime User
thks
 

stari

Active Member
Licensed User
Longtime User
And the best way for this :
{
"$token": "36ada5b10da39a1347559321baf13063",
"$distinct_id": "13793",
"$ip": "123.123.123.123",
"$set": {
"Address": "1313 Mockingbird Lane"
}
}
 

johndb

Active Member
Licensed User
Longtime User
Syntax checking is not ignored within multi-line smart strings.

The following single line smart string statement works:
B4X:
dim s as string = $"Sub xyz(var1, var2)"$

The following multi-line smart string statement fails as B4X thinks that it is code:
B4X:
dim s as string =  _
$"
sub xyz(var1, var2)
"$

All text within the multi-line string should not be checked at all.

Is this a bug?

[SOLVED] You must start a line with the $" and text and the last line must end with "$ on the same lines:
B4X:
dim s as string = _
$"Sub xyz (var1 as int, var2 as int) as int
return var1+var2
end sub"$

Thanks,

John
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
It took me a while to figure out this convoluted way, although someone else may find a much simpler string literal and make a fool out of my solution.
B4X:
Dim s As String = $"Sub${Chr(32 _
    )}xyz(var1, var2)
    "$
    Log(s)     'Displays: Sub xyz(var1, var2)
 

avalle

Active Member
Licensed User
Longtime User
Does a Smart String help dealing with long strings which should not contain CRLF?
Currently I'm dealing with them as such:

B4X:
resp.Write($"info="my long string...","$ & _
$"descr="my other long string","$ & _
$"etc etc..."$)

I would like to do it as such:

B4X:
resp.Write($"info="my long string...", & _
descr="my other long string", & _
etc etc..."$)

Any chance? Thanks for your advice.
 

JesseW

Active Member
Licensed User
Longtime User
If you need to use a string with a quote inside then escape it with double quotes:
in your CSVParser (which I greatly appreciate btw...) there is a line
B4X:
word = word.Replace(QUOTE, $""""$)
if I'm understanding smart strings correctly, this could have also been writen as
B4X:
word = word.Replace(QUOTE, """""")
is this correct?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…