Quinch Posted February 10, 2012 Share Posted February 10, 2012 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. Link to comment Share on other sites More sharing options...
UEZ Posted February 10, 2012 Share Posted February 10, 2012 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 comment Share on other sites More sharing options...
Quinch Posted February 10, 2012 Author Share Posted February 10, 2012 Yeah, that's basically what I meant. Alright, thanks anyway. Link to comment Share on other sites More sharing options...
Malkey Posted February 10, 2012 Share Posted February 10, 2012 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 comment Share on other sites More sharing options...
Quinch Posted February 10, 2012 Author Share Posted February 10, 2012 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. Link to comment Share on other sites More sharing options...
UEZ Posted February 10, 2012 Share Posted February 10, 2012 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 comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now