How to escape the percent symbol within transform command Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
LastDavid
Posts: 5
Joined: 27 Feb 2018, 23:57

How to escape the percent symbol within transform command

03 Dec 2019, 02:00

The following generates an error for illegal character due to the percent symbol after 100

strTest := "Today 100% of the testing was completed at %A_Hour%%A_Min%"
Transform, strTest, DeRef, %strTest%
Send %strTest%{return}

I have tried both 100`% and 100{%}

I would like the output to be:
Today 100% of the testing was completed at 2153

Any suggestions? Thank you for any help.
gregster
Posts: 3410
Joined: 30 Sep 2013, 06:48

Re: How to escape the percent symbol within transform command

03 Dec 2019, 02:13

LastDavid wrote:
03 Dec 2019, 02:00
Today 100% of the testing was completed at 2153
In this case, I wouldn't use Transform, , DeRef. But I don't think that I ever used it before :D (at least not DeRef)

This should be enough (see expressions, especially here):

Code: Select all

strTest := "Today 100% of the testing was completed at " A_Hour A_Min	; expression syntax
Send %strTest%{enter}	; I think the keyname 'enter' is more future-proof
LastDavid
Posts: 5
Joined: 27 Feb 2018, 23:57

Re: How to escape the percent symbol within transform command

03 Dec 2019, 02:25

Thank you for your suggestion, however it does not answer the question.

The example was just provided to highlight the problem and to provide common code to be used during the discussion.
gregster
Posts: 3410
Joined: 30 Sep 2013, 06:48

Re: How to escape the percent symbol within transform command  Topic is solved

03 Dec 2019, 02:36

Well, to solve the problem at hand, that means, getting the output you specified, this is probably the most common code usage that evaluates these variables (well, you could explicitly concatenate with ., like shown in the second link).

But if you insist to use transform, this seems to work:

Code: Select all

strTest := "Today 100``% of the testing was completed at %A_Hour%%A_Min%"
Transform, strTest, DeRef, %strTest%
Send %strTest%{return}
It's a very uncommon command, imho. I mean `` is the escape sequence for ` - but why this is necessary here, 🤷‍♂️
swagfag
Posts: 3086
Joined: 11 Jan 2017, 17:59

Re: How to escape the percent symbol within transform command

03 Dec 2019, 02:40

its ``% or ``{%}(if u will, doesnt make a difference)

o.O gregster is green now 👽

its because transform expands escape sequences as well. so after the transform one backtick goes away and then ure trying to Send some%text, which is invalid, so u have to put an additional backtick. that way transform escapes(``) the backtick, which then leaves u with just a single backtick
gregster
Posts: 3410
Joined: 30 Sep 2013, 06:48

Re: How to escape the percent symbol within transform command

03 Dec 2019, 02:49

Makes sense, thank you, swagfag!
o.O gregster is green now
Yeah :shock:, not sure how that happened ;)

Return to “Ask For Help”

Who is online

Users browsing this forum: dave444344, dead_line, Google [Bot], spencer and 213 guests