How to assign a long string (around 2m characters) to a variable Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

How to assign a long string (around 2m characters) to a variable

25 Jan 2019, 06:52

Hello, I'm asking this because I'm trying to find a good way to do this.
What I tried:

var := "2m string" Fails because a line can only contain around 16k characters.

Code: Select all

var := "16k string" .
. "16k string" .
...
Fails because Continuation section is too long.

Code: Select all

var = 
(
16k string
16k string
...
)
Fails because Continuation section is too long.

@edit: this is related to my post: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=61370&p=259975#p259975
kyuuuri
Posts: 340
Joined: 09 Jan 2016, 19:20

Re: How to assign a long string (around 2m characters) to a variable

25 Jan 2019, 07:00

I made the following after posting this:

Code: Select all

asd1 := "16k characters"
asd2 := "16k characters"
...
asd60 := "16k characters"
loop 60 ;amount of lines I have
{
	image .= asd%a_index%
}
Is there an easier or better way to do this without having so many variables?

@edit: or maybe there is a way to use a resource inside the script to get the image with GDIP (even if I use UPX or Mpress)
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to assign a long string (around 2m characters) to a variable

26 Jan 2019, 05:33

how to build long strings:

Code: Select all

s .= "long.."
s .= "long.."
s .= "long.."
...
cut up the base64 encoded image in ur editor or use a script to do it for u, ex:

Code: Select all

#NoEnv
#SingleInstance Force
SetBatchLines -1

isUnicode := A_IsUnicode ? 2 : 1

img64 := Clipboard

len := StrLen(img64)
MAX_CHARS := 16000

VarSetCapacity(out, len * A_IsUnicode + 20000)

out := "makeImgStr(ByRef s) {`n`tVarSetCapacity(s, " len " * A_IsUnicode ? 2 : 1)`n`n"

Loop % len / MAX_CHARS
{
	i := A_Index - 1
	offset := i * MAX_CHARS * isUnicode
	out .= "`ts .= """ StrGet(&img64 + offset, MAX_CHARS) """`n"
}
out .= "`ts .= """ StrGet(&img64 + (++i * MAX_CHARS * isUnicode)) """`n`n"
out .= "`treturn s`n}"

Clipboard := out
ExitApp
copy base64, run script, a function will appear in ur Clipboard, paste it in a new file, #Include it in ur main script, call makeImgStr(my_var_name) in ur main script, dont forget to clear the var when ure finally done with it

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], robodesign and 243 guests