Include Demiliters in StrSplit

Propose new features and changes
User avatar
labrint
Posts: 379
Joined: 14 Jun 2017, 05:06
Location: Malta

Include Demiliters in StrSplit

18 Jul 2017, 03:32

Create an option to include delimiters in strsplit arrays. Ideally an option to selectively include delimiters in strsplit arrays.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Include Demiliters in StrSplit

18 Jul 2017, 05:13

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)
}
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Include Demiliters in StrSplit

18 Jul 2017, 08:43

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
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Include Demiliters in StrSplit

02 Dec 2022, 20:55

There needs to be an option on which "side" to include delimiters.
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.

Return to “Wish List”

Who is online

Users browsing this forum: kunkel321 and 93 guests