Mat Posted April 1, 2009 Posted April 1, 2009 basically, I have a string $String = "111111111100000000000111000000000000000" now I need to get this: $Split = Stringsplit ($String) $Split[0] = 4 $Split[1] = "1111111111" $Spit[2] = "00000000000" $Split[3] = "111" $Split[4] = "000000000000000" I was trying this: $String = "111111111100000000000111000000000000000" $Split = Stringsplit ($String, "") $i = 1 Do $m = 1 $Done[$m] = $Split[$i] Do $n = 1 If $Split[$i + $n] = $Split[$i] Then $Done[$m] &= $Split[$i + $n] Else ExitLoop EndIf $m += 1 Until $n + $i = $Split[0] Until $i = $Split[0] MsgBox (48, "test", $Done) but no result. if it helps I can get away with only 2 different string values, but ideally it should cater for more.... I hope that code is useful, it's incredbly confusing, but do you see what I'm trying to do? I was using for loops, but do's became easier when I started mixing up values.... AutoIt Project Listing
JRowe Posted April 1, 2009 Posted April 1, 2009 This is more of a stringregexp function than a stringsplit function (although you could probably do it either way.) Something like this might work, returning an array of matches for multiple groupings of any character. StringRegExp("111111111100000000000111000000000000000", "(.+)" 2) [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center]
Mat Posted April 1, 2009 Author Posted April 1, 2009 ta muchly, never used that before, will try it out! won't be here for a week, so your better off pming me with any further answers. Thanks MDiesel AutoIt Project Listing
Stilgar Posted April 1, 2009 Posted April 1, 2009 Hello, I think you searching something like this: $s = "111111111100000000000111000000000000000" $a = StringRegExp($s,"[1]+|[0]+",3) _ArrayDisplay($a) jEdit4AutoIt PlanMaker_UDF Â Â
BrettF Posted April 2, 2009 Posted April 2, 2009 Does this work? #Include <Array.au3> $string = "111111111100000000000111000000000000000" $aStrings = _StringSplitByChange($string) _ArrayDisplay ($aStrings) Func _StringSplitByChange($sString) Local $iCount = 1 Local $asplit = StringSplit ($sString, "") Local $aRet[$asplit[0]] $aRet[1] = $asplit[1] For $i = 2 to $asplit[0] If $asplit[$i-1] <> $asplit[$i] Then $iCount += 1 $aRet[$iCount] &= $asplit[$i] Else $aRet[$iCount] &= $asplit[$i] EndIf Next ReDim $aRet[$iCount+1] $aRet[0] = $iCount Return $aRet EndFunc Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Malkey Posted April 2, 2009 Posted April 2, 2009 basically, I have a string $String = "111111111100000000000111000000000000000" now I need to get this: $Split = Stringsplit ($String) $Split[0] = 4 $Split[1] = "1111111111" $Spit[2] = "00000000000" $Split[3] = "111" $Split[4] = "000000000000000" I was trying this: $String = "111111111100000000000111000000000000000" $Split = Stringsplit ($String, "") $i = 1 Do $m = 1 $Done[$m] = $Split[$i] Do $n = 1 If $Split[$i + $n] = $Split[$i] Then $Done[$m] &= $Split[$i + $n] Else ExitLoop EndIf $m += 1 Until $n + $i = $Split[0] Until $i = $Split[0] MsgBox (48, "test", $Done) but no result. if it helps I can get away with only 2 different string values, but ideally it should cater for more.... I hope that code is useful, it's incredbly confusing, but do you see what I'm trying to do? I was using for loops, but do's became easier when I started mixing up values....This example groups any consecutive repeating characters and, individual non - repeating characters if they exist in the test string, into an array. If case sensitivity is required, remove "(?i)" from the beginning of the regular expression search pattern. #include <Array.au3> $sStr = "111111111100000000000111000000000000000CCcC11abBc d%%%!" ; Groups repeating characters & stand alone characters into an array. $aArray = StringSplit(StringTrimRight(StringRegExpReplace($sStr, "(?i)(.)(\1*)", "\1\2|"), 1), "|") _ArrayDisplay($aArray)
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