Defining string to variable containing both % and "

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
natester002
Posts: 11
Joined: 24 Jun 2019, 10:23

Defining string to variable containing both % and "

30 Jul 2021, 17:26

Hello all,

I may just be missing something obvious, so please be kind. It may also not be possible.

If I need to set a variable like so

var := "randomcharacterswith%insidehereorthere%andsometimesasinglequote"too"

I hit an error. It reads to the character in the string with the " as the extent of the variable and leaves (too") at the end which causes syntax issues.

If I do it this way below, it of course messes up as it makes the % % a variable that means nothing which reduces my string incorrectly.

var = randomcharacterswith%insidehereorthere%andsometimesasinglequote"too

The string comes from an encryption script so I can't guarantee it won't have the " or % periodically in it. https://autohotkey.com/board/topic/4147-small-and-fast-text-file-encryptor/page-4#:~:text=17%20Jun%202008-,I%20get%20a%20curious,-behavior%20with%20the

Is there a way to allow a string to just read a variable as it is and ignore the % function (again, I know the escape character ` will do it, but this is a generated string that can't be changed due to encryption).

Or, is there a way that the variable will accept all of the quoted material (minus string replacing " to "" which does the trick, but again, auto generated string here.

You can see exactly what I am talking about by using the code I linked above.

Code: Select all

var1 = mydecryptingpasswordkey
Encryptedmess := "VPv405y86i&+s%Aj6j}KzLtI10MzDj:!whW'xP)i8Adu/\ t^<j]"e-Y6"
Decrypted := TEA_DecryptString( Encryptedmess, var1 )
Msgbox, % Decrypted
To be clear, the var1 in this case will not decrypt anything as this was just to show my issue here in the forums. Encryptedmess (while valid in use as I got it from encrypting), is not able to be added to my script for a "key check" since I can't define it. The only thing I can think of is an iniwrite and an iniread to do this. If I need to, I will. Just figured I would check.

Thanks in advance for your brainpower (however little or large effort). :)
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Defining string to variable containing both % and "

30 Jul 2021, 17:41

1. Use expression syntax, command syntax should better not be used in new scripts

2. if the string contains ", it must be doubled. The variable in memory will contain only one ", the "" exists only in the source code.

3. In expression syntax, The percent sign % is like any other character inside a string

If you assign
var := "randomcharacterswith%insidehereorthere%andsometimesasinglequote""too"
var will contain the string
var := "randomcharacterswith%insidehereorthere%andsometimesasinglequote"too"

"" only in the source code - if the source code is generated automatically, you must process it to double all existing quotes in a string. But that's only in the source text, the variable itself contains the string without doubled quotes, so there should be no problem with encryption when you use the variable

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Google [Bot], ShatterCoder and 128 guests