Sign in to follow this  
Followers 0
Quinch

Non-destructive StringSplit?

6 posts in this topic

Just a quick question, is there a way to perform a StringSplit without deleting the actual delimiters? I know I can go back and reinsert them with a for-to, but I'm just curious if there's a neater way to do it.

Share this post


Link to post
Share on other sites



No need to add them separately because StringSplit returns an array and you can add manually the delimiter when you traverse the array for any reason.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Yeah, that's basically what I meant. Alright, thanks anyway.

Share this post


Link to post
Share on other sites

Here are two results from performing a StringSplit without deleting the actual delimiters. Where is the delimiter suppose to go?

#include <Array.au3>

Local $sTestString = "one_two_three_four_five"

Local $aArray = _StringSplitAfter($sTestString, "_", 1)
_ArrayDisplay($aArray, "Split After Delimiter")

Local $aArray1 = _StringSplitBefore($sTestString, "_", 3)
_ArrayDisplay($aArray1, "Split Before Delimiter")


Func _StringSplitAfter($sString, $sDelimiters, $iFlag = 1)
    If $iFlag = 0 Then $iFlag = 1
    If $iFlag = 2 Then $iFlag = 3
    Return StringSplit(StringReplace($sString, $sDelimiters, $sDelimiters & "<!@#>"), "<!@#>", $iFlag)
EndFunc   ;==>_StringSplitAfter

Func _StringSplitBefore($sString, $sDelimiters, $iFlag = 1)
    If $iFlag = 0 Then $iFlag = 1
    If $iFlag = 2 Then $iFlag = 3
    Return StringSplit(StringReplace($sString, $sDelimiters, "<!@#>" & $sDelimiters), "<!@#>", $iFlag)
EndFunc   ;==>_StringSplitBefore

Share this post


Link to post
Share on other sites

Preferably into the latter string. Either way, it's not that big a deal, I'm just trying to keep my code as tidy as possible otherwise things get a little... unnecessarily convoluted.

Share this post


Link to post
Share on other sites

Here are two results from performing a StringSplit without deleting the actual delimiters. Where is the delimiter suppose to go?

#include <Array.au3>

Local $sTestString = "one_two_three_four_five"

Local $aArray = _StringSplitAfter($sTestString, "_", 1)
_ArrayDisplay($aArray, "Split After Delimiter")

Local $aArray1 = _StringSplitBefore($sTestString, "_", 3)
_ArrayDisplay($aArray1, "Split Before Delimiter")


Func _StringSplitAfter($sString, $sDelimiters, $iFlag = 1)
    If $iFlag = 0 Then $iFlag = 1
    If $iFlag = 2 Then $iFlag = 3
    Return StringSplit(StringReplace($sString, $sDelimiters, $sDelimiters & "<!@#>"), "<!@#>", $iFlag)
EndFunc   ;==>_StringSplitAfter

Func _StringSplitBefore($sString, $sDelimiters, $iFlag = 1)
    If $iFlag = 0 Then $iFlag = 1
    If $iFlag = 2 Then $iFlag = 3
    Return StringSplit(StringReplace($sString, $sDelimiters, "<!@#>" & $sDelimiters), "<!@#>", $iFlag)
EndFunc   ;==>_StringSplitBefore

Nice idea Malkey!

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0