string split results

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
codude
Posts: 128
Joined: 12 Nov 2015, 05:33

string split results

23 Oct 2018, 09:46

When I run this

str = Red Green Blue \Big\Small\Med

s:=StrSplit(str,"\")
T1:= s.1
T2:= s.2

MsgBox % T1
MsgBox % T2

T1 is good for me but T2 equals "Big". I want "\Big|Small\Med" (With all 3 back slashes). In some cases there may be more or less back slashes. I just want everything after the first one including that first back slash. Thanks
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: string split results

23 Oct 2018, 10:20

maxparts:

Code: Select all

str = Red Green Blue \Big\Small\Med
a := StrSplit(str, "\", , 2)
MsgBox % a[1]
MsgBox % a[2]
codude
Posts: 128
Joined: 12 Nov 2015, 05:33

Re: string split results

23 Oct 2018, 11:50

Thanks for taking the time to respond here. I'm getting a error here. "Error: Too many parameters passed to Function" I went back to the AHK String Split page and tried to change a few things but I'm not able to get this.
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: string split results

23 Oct 2018, 12:01

Update to the most recent version and the error should go away. (I tested it myself on version 1.29)
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: string split results

23 Oct 2018, 12:36

Latest release is assumed unless otherwise explicitly specified.

If you can't update, you can parse it with a regexp instead.
regexmatch(haystack, "([^\\]*)(.*)", match)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: string split results

23 Oct 2018, 12:42

And via InStr. Cheers.

Code: Select all

q::
vText := "Red Green Blue \Big\Small\Med"
if (vPos := InStr(vText, "\"))
	vText1 := SubStr(vText, 1, vPos-1), vText2 := SubStr(vText, vPos+1)
else
	vText1 := vText, vText2 := ""
MsgBox, % "[" vText1 "]" "`r`n" "[" vText2 "]"
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
codude
Posts: 128
Joined: 12 Nov 2015, 05:33

Re: string split results

23 Oct 2018, 13:31

I've got so much to learn here. I've been trying to get by with 1.21 for years now because I did not want to mess with what seemed like a good thing. I went ahead and updated to 1.30 and the original script from swagfag now works fine and so far everything else seems to be okay. I guess time will tell. Thank you all for the input here.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Google [Bot], Joey5, Nerafius, RandomBoy and 155 guests