Include Demiliters in StrSplit
Include Demiliters in StrSplit
Create an option to include delimiters in strsplit arrays. Ideally an option to selectively include delimiters in strsplit arrays.
Re: Include Demiliters in StrSplit
Hello. I gave you a more specific example in you ask-for help topic. I give a more general example here, if some one is interested. There needs to be an option on which "side" to include delimiters.
Code: Select all
; Example:
a:="abc(123)hello,string|split"
a:=strSplitInclude(a,[",","|"],["(",")"],["L","R"])
for k, v in a
str.=v "`n"
Msgbox, % str
strSplitInclude(String, Delimiters:="", IncludeDelimiters:="", includeSide:="R",OmitChars:=""){
; Delimiters, not included in the array
; IncludeDelimiters, a list (array) of delimiters to include after the split.
; IncludeSide, for each delimiter in IncludeDelimiters specify if the delimiter is to be included to the left "L" or right, "R".
; If omitted all delimiters are included to the right. You can specify "L" to let all delimeters be on the left side.
;
static del:=chr(1)
if !IsObject(Delimiters)
Delimiters:=[Delimiters]
for k, Delimiter in Delimiters
String:=StrReplace(String, Delimiter, del)
if !IsObject(IncludeDelimiters)
IncludeDelimiters:=[IncludeDelimiters]
if !IsObject(includeSide){
t:=[]
loop % IncludeDelimiters.length()
t.push(includeSide)
includeSide:=t
}
for k, Delimiter in IncludeDelimiters
String:=StrReplace(String, Delimiter, includeSide[k]="R" ? Delimiter . del : del . Delimiter)
return strsplit(String, Del, OmitChars)
}
Re: Include Demiliters in StrSplit
For the specific example that seems to have inspired this, and a simple solution, see:
REGEXMATCH OR STRSPLIT - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 55#p160055
REGEXMATCH OR STRSPLIT - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 55#p160055
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Include Demiliters in StrSplit
I would expect the delimiters to be included as elements in the array, so every second element is a delimiter. If they are included as a suffix or prefix to the delimited value, differentiating delimiters of different lengths becomes difficult.There needs to be an option on which "side" to include delimiters.
Who is online
Users browsing this forum: No registered users and 24 guests