Page 1 of 1

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

Posted: 25 Jan 2019, 06:52
by kyuuuri
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

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

Posted: 25 Jan 2019, 07:00
by kyuuuri
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)

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

Posted: 25 Jan 2019, 07:52
by IMEime
you do not post any kind of 'real' code so there is nothing I can do

just check this out
https://www.autohotkey.com/docs/Objects.htm#Usage_Simple_Arrays

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

Posted: 25 Jan 2019, 07:52
by IMEime

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

Posted: 25 Jan 2019, 08:02
by kyuuuri
I will try with the arrays, thank you!

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

Posted: 26 Jan 2019, 05:33
by swagfag
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