maniootek Posted December 19, 2014 Posted December 19, 2014 I want to cut my string into 8 digit long pieces $string = "42383298472398472389472398472389" and place each result into array $aResult = StringCut($string, 8) any idea?
Solution Malkey Posted December 19, 2014 Solution Posted December 19, 2014 Here is one method. #include <Array.au3> $string = "42383298472398472389472398472389" $array = StringRegExp($string, "\d{8}", 3) ; From left to right, match 8 digits continuously. _ArrayDisplay($array)
Guest Posted December 19, 2014 Posted December 19, 2014 If you want to learn how it can be done without StringRegExp() then: #include <Array.au3> $string = "42383298472398472389472398472389" $test = StringCut($string,8) _ArrayDisplay($test," (Line: "&@ScriptLineNumber&")") Func StringCut($string,$numb) Local $tmp1,$tmp2[1] $tmp2[0] = 0 $tmp1 = $string Do _ArrayAdd($tmp2,StringLeft($tmp1,$numb)) $tmp2[0] += 1 $tmp1 = StringTrimLeft($tmp1,$numb) Until $tmp1 = '' Return $tmp2 EndFunc
andrewz Posted December 19, 2014 Posted December 19, 2014 (edited) U could also do it this way: Count lenght --> divide it by 8 = x --> StringTrimRight by 8 x times and StringTrimLeft by times ran--> substract 1 from x -> Save into Array --> Do untill x = 0. There are so many possible ways, tho Malkey's solution looks like the "cleanest" and maybe is even the best resource wise. EDIT: Here u go, just with a massagebox tho... : #include <Array.au3> $string = "42383298472398472389472398472389" $lenght = StringLen($string) $timestorun = $lenght/8 $timesran = 0 Do $timestorun -= 1 $cut_A = $timestorun *8 $cut_B = $timesran *8 $string_A = StringTrimRight($string,$cut_A) $string_B = StringTrimLeft($string_A,$cut_B) $timesran += 1 MsgBox(0,"",$string_B) Until $timestorun = 0 Edited December 19, 2014 by andrewz
kylomas Posted December 20, 2014 Posted December 20, 2014 (edited) This handles strings if not a multiple of 8... #include <Array.au3> $string = "4238329847239847238947239847239876" $array = StringRegExp($string, "\d{1,8}", 3) ; From left to right, match 8 digits continuously. _ArrayDisplay($array) kylomas Edited December 20, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
mikell Posted December 20, 2014 Posted December 20, 2014 And for the regex hostiles... #include <Array.au3> $string = "423832984723984723894723984723895" Local $r[0] For $i = 1 to StringLen($string) step 8 _ArrayAdd($r, StringMid($string, $i, 8)) Next _ArrayDisplay($r)
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