new
new

Reputation: 1159

Escape and replace quotations in VBS

I need to escape the character " by replacing it in vbs

I write

 str=8505usafromTo^1c0"ma
 str = replace(str,chr(34),"""")

But it seems like " does not escape for the string str

Please, what's wrong and someone could help me fix that?

Thanks

Upvotes: 1

Views: 6752

Answers (1)

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38775

String literals need double quotes:

str = "8505usafromTo^1c0 ma"

To escape a double quote in a string literal, use "" (double double quotes)

str = "8505usafromTo^1c0""ma"

It makes no sense to a replace double quotes (Chr(34)) in a string with double quotes ("""").

Update:

If you .ReadAll()/.ReadLine() a string from a file and want to change the " in that string, use

str = Replace(str, """", "that's what I want to see instead of each double quote")

In case you want "" (double double quotes) as replacements, you need """""" (2 delimiters and two times two double quotes).

Upvotes: 1

Related Questions