String bug ...

francoisg

Active Member
Licensed User
Longtime User
Hi,
when I do something like the following:

Dim s As String
s = "this is a ""quoted"" string"


Code highlighting works 100% in the IDE editor but when I try to compile I get ...

------------------------------------------------------------------------
Compiling code. Error
Error parsing program.
Error description: Syntax error.
Occurred on line: 70
s = "this is a ""quoted"" string"

------------------------------------------------------------------------

Obviously I can go "s = "This is a " & QUOTE & "quoted" & QUOTE " string" but that's just stupid!
 

SteveBee

Member
Licensed User
Longtime User
I confirm this behavior - B4a doesn't like the "" construct.

I encountered it when doing a string replace:
... .Replace("""", ...
Caused a GPF

... .Replace(chr(34), ...
Was ok.
 

kickaha

Well-Known Member
Licensed User
Longtime User
Be interested to hear why that is "just stupid" ( or should that be QUOTE&"just stupid"&Quote), as it is pretty similar to other languages.
 

splatt

Active Member
Licensed User
Longtime User
Hi,
Obviously I can go "s = "This is a " & QUOTE & "quoted" & QUOTE " string" but that's just stupid!

This is just standard string concatenation. It's what you would expect to do!
 

SteveBee

Member
Licensed User
Longtime User
Of course none of this actually addresses the original issue - that using "" causes a code failure.
 

eps

Expert
Licensed User
Longtime User
No programming language will handle quotes in strings, it just doesn't work, how would you expect a compiler or interpreter to understand that it's a quote which is part of a string as opposed to a quote which ends a string..
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
No programming language will handle quotes in strings, it just doesn't work, how would you expect a compiler or interpreter to understand that it's a quote which is part of a string as opposed to a quote which ends a string..

I went to the Immediate window of VB6 and typed the first line and it responded with the second line:

B4X:
Print "This is a ""quote"" from VB6."
This is a "quote" from VB6.

It can understand that it's a quote because 2 in a row = a quote in the text while a single quote ends a string.
 

barx

Well-Known Member
Licensed User
Longtime User
ASP (vbscript) is the same "" = quote. Though I won't be looking sleep over it lol

Sent from my Desire Z
 

francoisg

Active Member
Licensed User
Longtime User
"Stupid" because it make reading the code harder - changing it afterwards and keeping things in the correct place is an issue as well.

I just like my code to be as neat and tidy as possible! And the comment "No programming language will handle quotes in strings..." - that's just funny ;-)

Can we confirm that the translator / compiler handles this incorrectly? Especially as the code highlighting works as expected in the IDE??? So can we either change code highlighting to NOT display it as I expect to do or fix the translator (should be easy enough to do???) ???

Still, this is one of the easiest ways to code for Android. Please do not see this post as criticism!!! I think all of us wants the best possible product - for the publisher that means more sales ;-)

Regards,
Marius le Roux
(South Africa)
 
Top