Escaping quotes and hash character

Get help with using AutoHotkey and its commands and hotkeys
flipside555
Posts: 2
Joined: 04 Jan 2019, 03:33

Escaping quotes and hash character

04 Jan 2019, 03:45

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.
User avatar
Scr1pter
Posts: 1069
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Escaping quotes and hash character

04 Jan 2019, 08:51

I don't think you need this: `#
Just #
Please use code tags when posting code!
Keyboard: Logitech G15 FE - Mice: Logitech G9 FE, G502 FE, G602 - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.29.00
User avatar
TheDewd
Posts: 1288
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Escaping quotes and hash character

04 Jan 2019, 08:52

Code: Select all

SendTag := "<font color=""#00FF00"">" Clipboard "</font>"
You need to use double-quotes.
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
Rohwedder
Posts: 1991
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Escaping quotes and hash character

04 Jan 2019, 09:01

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>
User avatar
Delta Pythagorean
Posts: 464
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: Escaping quotes and hash character

04 Jan 2019, 14:25

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.
swagfag
Posts: 2610
Joined: 11 Jan 2017, 17:59

Re: Escaping quotes and hash character

04 Jan 2019, 15:14

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
flipside555
Posts: 2
Joined: 04 Jan 2019, 03:33

Re: Escaping quotes and hash character

04 Jan 2019, 23:11

Thanks for the replies. This is the working version.

Code: Select all

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

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], fernsehen123, maleko48, Sabestian Caine, teadrinker and 145 guests