pasting raw text into an array without fixing escape characters Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

pasting raw text into an array without fixing escape characters

21 May 2018, 20:15

I am currently working on a script that requires me to take tons of raw text and paste it into my script in an array/arrays.

The issue would be that the text contains escape characters and I really don't want to have to go over even one line of the text to correct for it. ie. ' " ' becomes ' "" ' etc.

I know that I can first put the text in a var like this:
var = my_function(a,&b,c:="")

and then add var to my array
array[index]:=var

But... I think I would go crazy long before I got a fraction through it.

So what I need is a way to just copy and paste any raw text and know that there is not going to be any issues with any possible
escape characters.


Thanks in advance for any assistance.
Hellbent.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: pasting raw text into an array without fixing escape characters

21 May 2018, 21:01

It occurs to me that this is a much more complicated problem then I first assessed.

I suspect that even if most escape sequences could be dealt with, comments ";" "~;" "/* */" would still be a hold up.
I really didn't want to have to do this as a script and a text doc but it seems that it is going to be the case.

For the moment i'll leave this thread as a active one, but it seems to me to likely something undoable without doing something like having the script read and parse itself with the text being in a comment at the bottom or something like that.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: pasting raw text into an array without fixing escape characters

21 May 2018, 21:38

- If you want to put verbatim text into a script, and assign that text to a variable, you could use a continuation section, or use FileRead to read text from a file.
- For a continuation section example see: ANSI (CP-1252) CHARACTERS (VERBATIM), here:
jeeswg's characters tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=26486
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: pasting raw text into an array without fixing escape characters  Topic is solved

21 May 2018, 21:43

Solution achieved.

Code: Select all

#SingleInstance,Force

Fileread,temp,some script name.ahk

My_Array:=StrSplit(temp,"•")

Loop 2
	My_Array.Remove(1)

msgbox,% My_Array[1]  ; output = function_1(` , `n , &, ", `t, ; , /* , */ , ;~ )


ExitApp

/*

•
function_1(` , `n , &, ", `t, ; , /* , */ , ;~ )
•
function_2(a,b,c:="")
•
etc.
*/

User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: pasting raw text into an array without fixing escape characters

21 May 2018, 21:55

jeeswg wrote:- ANSI (CP-1252) CHARACTERS (VERBATIM), here:
jeeswg's characters tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=26486

Dealing with text is something that I find very dry and have tried to stay away from anything to do with boring text as much as I can. I guess it's largely because I hate (HATE) typing or reading off a computer screen.

Would you mind showing me how I would put this as it is exactly into the - ANSI (CP-1252) CHARACTERS (VERBATIM)

Code: Select all

/*
; notes 
; more notes
function_1(` , `n , &, ", `t, ; , /* , */ , ;~ )
*/
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: pasting raw text into an array without fixing escape characters

21 May 2018, 22:38

NVM worked it out.
Cool trick, it looks like I would still have to add it to my array in another step on top of having to type out
(%` Join`r`n
)
for every index.
I think i'll go with the solution I came up with for this project, but I'm sure the continuation section will come in handy down the road.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: pasting raw text into an array without fixing escape characters

21 May 2018, 22:46

- Well, I had in mind perhaps putting text in front of each line, to indicate the key names. Then using a parsing loop on each line. E.g. 'abc' -> 'key1:abc', then use the first colon as an indicator to where the key name ends and the value text begins while parsing.
- You could also use StrSplit and refer to each line by its number.
- Another possibility is to copy the text, replace special characters, and paste the text, and then work on that text manually for use with your script.
- Lots of possibilities.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: pasting raw text into an array without fixing escape characters

21 May 2018, 23:05

Thanks for the ideas,
Currently working on setting it up with a mix of the continuation section and the special characters.
If that fails I'll take a look at one of the methods you mentioned.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 343 guests