Page 1 of 1

StrReplace - escaping doublequotes failing - why?

Posted: 27 Jan 2023, 02:51
by dwilbank
So I'm trying to change the language text here by targeting the "en-US" with its actual surrounding quotes as well as adding in "ko" with its actual surrounding quotes

<tt xml:lang="en-US" ...

Code: Select all

newXML := StrReplace(theXML, "xml:lang=""en-US"", "xml:lang=""ko"")
newXML := StrReplace(theXML, "xml:lang=""en-US"", "xml:lang=""ko""")
Both of these fail though, with AHK's error saying that ko is somehow being read as an illegally named variable

Is there some other way to escape these?

Re: StrReplace - escaping doublequotes failing - why?  Topic is solved

Posted: 27 Jan 2023, 03:00
by gregster
Afaics, you have in both cases no closing quote in the second parameter, the Needle. Try
newXML := StrReplace(theXML, "xml:lang=""en-US""", "xml:lang=""ko""")

Code: Select all

newXML := StrReplace(theXML, "xml:lang=""en-US""", "xml:lang=""ko""")

Re: StrReplace - escaping doublequotes failing - why?

Posted: 27 Jan 2023, 03:07
by dwilbank
The old triple-quote conundrum again.
Thanks sir!

Re: StrReplace - escaping doublequotes failing - why?

Posted: 27 Jan 2023, 05:13
by boiler
dwilbank wrote: The old triple-quote conundrum again.
Instead of thinking of it as triple quotes, just think that you need a quote at the start and end of your string, and anywhere inside that where you want a quote character, you need two of them. Trying to remember special cases where there are three in a row is unnecessary and just makes it confusing.