Escaping quotes and hash character

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
flipside555
Posts: 25
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: 1275
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][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
User avatar
TheDewd
Posts: 1513
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.
Rohwedder
Posts: 7669
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: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

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.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

swagfag
Posts: 6222
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: 25
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 (v1)”

Who is online

Users browsing this forum: bonobo, masterkomp, OrangeCat, ruespe, Scr1pter, Spawnova, yuu453 and 379 guests