Escaping Quotes

I know I can create a string like this

s="my name is "+chrb(34)+"Dave"+chrb(34)

but I have a lot of literal strings (an no, I don’t want to put them in an external file)

I thought there was a way to create escaped strings… something like

s="my name is \"Dave\""

Am I daft (wait… don’t answer that!)
Am I mistaken :slight_smile:

s = “my name is ““Dave”””

I was afraid of that… I hate that method :slight_smile:

Put the strings that need escaping in a constant? Then you don’t need to worry about escaping quotes.

Why not use a method that returns a string and use for instance grave () instead of chr(34). Then you use the method as msg quote("My name is Dave`")

Not sure it is much better than “” though.

“” would be easier to deal with if the IDE color coded them. Many text editors will color code ANSI escape characters in a string. Imagine if s = "my name is ""Dave""" the “” in the string were to appear in red. It’d be a whole lot easier.

[quote=87880:@Dave S]I know I can create a string like this

s="my name is "+chrb(34)+"Dave"+chrb(34)

Yeah dont do this - this is probably the least desirable way to do this
You’ll end up with nil encoded strings :slight_smile:

  1. Just double up contained quotes
  2. use the UTF8 code point instead
    s="my name is " + &u22 + “Dave” + &u22

You could always write a little function, too, so you could then say:

s = "my name is " + inQuotes(“Dave”)

Isn’t it easier just to double up the quotes?

Much more efficient also. A method call is expensive as is string concatenation. I don’t like “” escapes, but I learned to deal with it, it is what it is.

I dislike them too, but the IDE is your friend - just check out the color of the text.

Yes, and that’s what I do, but if someone doesn’t like the look of so many quotes in a row a function would be another option.

after dinking around… I decided that doubled double quotes is the best way after all… and like Wayne said…

The IDE is my friend…(and friend who however has a ton of other annoying habits, but that is not the topic of THIS thread :slight_smile: )