The code snippet I'll provide is part of something much larger that works, but is pretty self contained. I really only need to understand what I'm doing ass backwards here. Programming in C++, I've made some really gnarly string manipulation programs that took crazy text files and cut them into readable formats for programs, but I can barely find and or use the string manipulation functions here without tripping up in some which way.
This snippet will put up an input box to ask you for names. For this example, I'll put in "Alex Brandon Casey Dave", it'll add a space on the end because I'm too lazy to add a special case where it reaches the end and must grab the rest of the string, and it'll keep finding spaces and add the previous string until there are no more spaces left, adding them all into an array. It will then read the array back to me one at a time and then say how big the array is. I know that's pretty useless, just reading it back, it's the easiest way to see that I'm correctly turning a long string full of spaces into an array that divides it all up. Please tell me how I can optimize it. I've considered also making input boxes until you no longer input something, and you can insert them all into an array that way so they are divided up way easier but I don't like that, I wanna play with strings.
Code: Select all
global NameList := Object()
^9::
NameList := Object()
InputBox, names, Users, Enter names with spaces inbetween, , 500, 300
names := names . " "
loop
{
ToFind := " "
StringGetPos, pos, names, %ToFind%
if (pos = -1)
{
ToolTip done
break
}
TempString := SubStr(names,1,pos)
NameList.Insert(TempString)
names := SubStr(names,pos+2)
}
index := 1
while index <= NameList.MaxIndex()
{
TempSave := NameList[index]
ToolTip %TempSave%
Sleep 500
index += 1
}
Maxs := NameList.MaxIndex()
ToolTip %Maxs%
Sleep 500
return