Page 1 of 1

Escaping quotes and hash character

Posted: 04 Jan 2019, 03:45
by flipside555
I'm trying to concatenate the clipboard with some text to produce the following line

Code: Select all

<font color="#00ff00">[Clipboard]</font>
I've tried various escape sequences but cannot get it working. This version

Code: Select all

SendTag := "<font color=`"`#00ff00`">" . Clipboard . "</font>"
produces this error
The following variable name contains an illegal character:"00ff00""
When I hit the back tick key on my keyboard, nothing happens. If I hit it again, two back ticks are created. I don't know if that is related to the problem. I've also tried copying the back tick character from the Autohotkey documentation.

Re: Escaping quotes and hash character

Posted: 04 Jan 2019, 08:51
by Scr1pter
I don't think you need this: `#
Just #

Re: Escaping quotes and hash character

Posted: 04 Jan 2019, 08:52
by TheDewd

Code: Select all

SendTag := "<font color=""#00FF00"">" Clipboard "</font>"
You need to use double-quotes.

Re: Escaping quotes and hash character

Posted: 04 Jan 2019, 09:01
by Rohwedder
Hallo,
back tick key is called a dead key: https://en.wikipedia.org/wiki/Dead_key
Without double-quotes:

Code: Select all

SendTag = <font color="#00ff00">%ClipBoard%</font>

Re: Escaping quotes and hash character

Posted: 04 Jan 2019, 14:25
by Delta Pythagorean
AHK tends to have a bit of a lazy day when it comes to using escape characters, and double quotes are no exception. To put it simply, double quotes, turn into quadruple quotes. It's weird, makes no sense, and annoys me to high hell, but I got used to it by having my editor highlight certain escape characters in a certain color.

Re: Escaping quotes and hash character

Posted: 04 Jan 2019, 15:14
by swagfag
how does it not make sense? it makes perfect sense. if ure in the context of a string(expression mode), to produce a literal ", escape it by prepending it with a ". it doesnt get any simpler than that

tbh if u got more quotes to escape than variables to shove in, do it the way Rohwedder showed
if u got an equal amount, Format() may be the tool to keep u sane

Re: Escaping quotes and hash character

Posted: 04 Jan 2019, 23:11
by flipside555
Thanks for the replies. This is the working version.

Code: Select all

SendTag := "<font color=""{#}00ff00"">" . Clipboard . "</font>"