Create a string from an array without looping

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
joefiesta
Posts: 497
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Create a string from an array without looping

19 Feb 2018, 08:33

Stringsplit nicely creates an array (pseudo or real) from a string.

Is there a way to create a string from an array WITHOUT USING A LOOP? I believe the array would have to be an object (not a "pseudo" array).

Put more simply: Does Stringsplit have a converse?

I'm using Stringsplit to create an array from an .INI file entry. Then use the array's values in my script. And then store any changes back to the .INI file (not that the .INI part has anything to do with this question).
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Create a string from an array without looping

19 Feb 2018, 10:19

Is there a way to create a string from an array WITHOUT USING A LOOP? I believe the array would have to be an object (not a "pseudo" array).
Well, if the number of elements in your array is static/known, no big deal ...

Code: Select all

array := StrSplit("bla blu blo bli", " ")
MsgBox % string := array[3] "`n" array[1] "`n" array[2] "`n" array[4]
Loop-phobics favourite (but annoying) thing!

Beware. Loops ahead!
Spoiler
joefiesta
Posts: 497
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: Create a string from an array without looping

20 Feb 2018, 10:29

@Bobo oooh, is that ugly.... But, thanks, and, no my array varies. I think that's the point. I'm no loopaphobe... just thought it would be much more than it works out to be.

it's so easy, I don't even think it would be worth having a command. I just learned FOR, so the loop is not ugly and probably as fast as any builtin command.

Code: Select all

  for kk,value in myarray                   ; loop, getting each KKth item, storing in VALUE
         mystring .= "," . value
 mystring := substr(mystring,2)
       
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: Create a string from an array without looping

20 Feb 2018, 11:04

For loops are easily my favorite loop since I found out about them. Another dead simple for loop that is really handy when dealing with arrays:

Code: Select all

for index, value in haystack
	if (value = needle)
		return index
return 0
Spent a while wondering why AutoStar has no native Object.Contains() function until I realized writing one is literally three lines of code. :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 299 guests