DicatoroftheUSA Posted July 9, 2010 Share Posted July 9, 2010 Here is a function. I am just looking for advice on how to make it more elegant/lean/robust.The goal is to make a stringsplit type function, that uses a regular expression as a deliminator.It returns an array containing what is between the deliminators, and [0]= delimitation string.I tried writing it using stringsplit and _arrayconcanate but I had issues, with memory, with very large strings.expandcollapse popup#include <Array.au3> ;~ ---for example $sString="abc124bcd2cde3def4efg" $sRegExp="[0-9]" $aResult=_REsplit($sString,$sRegExp) _arraydisplay($aresult) $sRegExp="124" $aResult=_REsplit($sString,$sRegExp) _arraydisplay($aresult) $sRegExp="[cd]" $aResult=_REsplit($sString,$sRegExp) _arraydisplay($aresult) ;~------ Func _RESplit($sString, $sRegExp) Local $aReturn[1] $aReturn[0]=$sRegExp $aSplits = StringRegExp($sString, $sRegExp, 3) For $x = 0 To UBound($aSplits) - 1 if StringInStr($sString, $aSplits[$x]) then $iLeft = StringInStr($sString, $aSplits[$x])-1 $iRight = StringLen($sString)-($iLeft+stringlen($aSplits[$x])) _ArrayAdd($aReturn, StringLeft($sString, $iLeft)) $sString = StringRight($sString, $iRight) EndIf Next _ArrayAdd($aReturn, $sString) Return($aReturn) EndFunc ;==>_RESplit Statism is violence, Taxation is theft. Autoit Wiki Link to comment Share on other sites More sharing options...
Mat Posted July 9, 2010 Share Posted July 9, 2010 $aReturn = StringRegExp($sString, "(?:(.*?)" & $sRegExp & ")", 3) _ArrayInsert($aReturn, 0, $sRegExp) Does that do it? You may want to set some options for the regex... AutoIt Project Listing Link to comment Share on other sites More sharing options...
DicatoroftheUSA Posted July 12, 2010 Author Share Posted July 12, 2010 (edited) $aReturn = StringRegExp($sString, "(?:(.*?)" & $sRegExp & ")", 3) _ArrayInsert($aReturn, 0, $sRegExp) Does that do it? You may want to set some options for the regex... Thanks. but no, the added strings cause it to behave almost oppositely of what I desire. The script is to work as stringsplit(), but to accept regular expressions as deliminators. I am just looking for proper coding, idiot proofing, and code efficiency tips before I put it on the example scripts board to get flamed. Edited July 12, 2010 by DicatoroftheUSA Statism is violence, Taxation is theft. Autoit Wiki Link to comment Share on other sites More sharing options...
Mat Posted July 12, 2010 Share Posted July 12, 2010 can you give an example of what you want the output to be then... I'm not sure I understand what you are trying to do... This gets exactly the same results as your function on all three of you examples, so unless your function isn't doing what you want it to do Func _RESplit2($sString, $sRegExp) $aReturn = StringRegExp($sString, "(?:(.*?)(?:" & $sRegExp & "|\z))", 3) _ArrayInsert($aReturn, 0, $sRegExp) _ArrayPop($aReturn) Return $aReturn EndFunc AutoIt Project Listing 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