[Solved] Get last variable from StrSplit.

Get help with using AutoHotkey and its commands and hotkeys
dsewq1LYJ
Posts: 114
Joined: 26 Aug 2014, 23:21

[Solved] Get last variable from StrSplit.

13 Sep 2015, 09:45

Hi !
I met a problem...

Variable ... Why not !?

Code: Select all

aStr=A\B\C\D
MsgBox % StrSplit(aStr, "\")[StrLen(RegExReplace(aStr, "\\"))]
but what If I dont ?
Is it not a feature or it's not necessary !? (Overcomplicated or I am too dumb :shock: )

Code: Select all

MsgBox % StrSplit("A\B\C\D", "\")[-1]
Last edited by tomoe_uehara on 13 Sep 2015, 11:49, edited 1 time in total.
Reason: Marked as solved
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Get last variable from StrSplit.

13 Sep 2015, 09:52

Code: Select all

aStr=A\B\C\D
obj := StrSplit(aStr, "\")
MsgBox, % obj[obj.Maxindex()]
or

Code: Select all

aStr=A\B\C\D
MsgBox, % StrSplit(aStr, "\").Pop()
Quick edit: Although, I think StrSplit is overkill if you just want the last item. I might be inclined to used InStr/SubStr/ or RegExMatch instead.
dsewq1LYJ
Posts: 114
Joined: 26 Aug 2014, 23:21

Re: Get last variable from StrSplit.

13 Sep 2015, 09:58

kon wrote:

Code: Select all

aStr=A\B\C\D
obj := StrSplit(aStr, "\")
MsgBox, % obj[obj.Maxindex()]
or

Code: Select all

aStr=A\B\C\D
MsgBox, % StrSplit(aStr, "\").Pop()
Quick edit: Although, I think StrSplit is overkill if you just want the last item. I might be inclined to used InStr/SubStr/ or RegExMatch instead.
OMG...
.Pop() :oops:

Thanks bro :headwall:

I should reread the docs :roll:

Return to “Ask For Help”

Who is online

Users browsing this forum: AHK_user, PebblyBeachBum, Robbl, zcw1030 and 50 guests