Jump to content

Non-destructive StringSplit?


Recommended Posts

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...