mmavipc Posted March 15, 2008 Posted March 15, 2008 I am trying to split a 12 character string into a array with earch array containing 3 letters here's my code: func _ss($s,$n) dim $return[1] if IsInt(Stringlen($s)/$n) then redim $return[Stringlen($s)/$n + 1] $return[0] = Stringlen($s)/$n Else MsgBox(0,IsInt(Stringlen($s)/$n),"hi") redim $return[int(Stringlen($s)/$n) + 2] $return[0] = int(Stringlen($s)/$n) + 1 EndIf msgbox(0,"",Stringlen($s)/$n) $c = 0 $num = 1 MsgBox(0,"",stringlen($s)) for $i = 1 to Stringlen($s) $c = $c + 1 if IsInt($i/$n) and $i <> Stringlen($s) then $num = $num + 1 ConsoleWrite($num & @lf) $return[$num] = $return[$num] & StringMid($s,$i,1) $c = 0 Else $return[$num] = $return[$num] & StringMid($s,$i,1) EndIf Next return $return EndFunc This is what it does say you have this string "123456789123" and you split it into and array with each array having 3 characters $a[0] would equal 4 like expected $a[1] would only have 2 characters "12" $a[2] and $a[3] would have 3 characters like expected $a[4] would have 4 letters Can anybody help me please? Thanks in advanced. [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N
Moderators SmOke_N Posted March 15, 2008 Moderators Posted March 15, 2008 (edited) Can you show what: $a[0] $a[1] $a[2] $a[3] $a[4] Literally would contain? Because it seems you are jumping around to me. Edit: This is how I understand you:#include <array.au3> $sString = "123456789123" $a = StringRegExp($sString, "(..)(...)(...)(....)", 3) _ArrayDisplay($a) Edited March 15, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
mmavipc Posted March 15, 2008 Author Posted March 15, 2008 $a[0] = "4" $a[1] = "12" $a[2] = "345" $a[3] = "678" $a[4] = "9123" array 1 and array 4 are messed up [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N
Moderators SmOke_N Posted March 15, 2008 Moderators Posted March 15, 2008 (edited) mmavipc said: $a[0] = "4" $a[1] = "12" $a[2] = "345" $a[3] = "678" $a[4] = "9123" array 1 and array 4 are messed up#include <array.au3> $sString = "123456789123" $a = _myStringFunc($sString) _ArrayDisplay($a) Func _myStringFunc($sString, $sPattern = "(..)(...)(...)(....)") Local $aSRE = StringRegExp($sString, $sPattern, 3) Local $nUBound = UBound($aSRE), $avArray[$nUBound + 1], $iCC $avArray[0] = $nUBound For $iCC = 0 To $nUBound - 1 $avArray[$iCC + 1] = $aSRE[$iCC] Next Return $avArray EndFunc Edit: Added #include Edited March 15, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
mmavipc Posted March 15, 2008 Author Posted March 15, 2008 that code does the exact same thing as SS which is not that i want i want $a[0] = 4 $a[1] = 123 $a[2] = 456 $a[3] = 789 $a[4] = 123 and if the string was 123456789123456789123(21 characters long) I would want it to do $a[0] = 7 $a[1] = 123 $a[2] = 456 $a[3] = 789 $a[4] = 123 $a[5] = 456 $a[6] = 789 $a[7] = 123 [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N
Moderators SmOke_N Posted March 15, 2008 Moderators Posted March 15, 2008 mmavipc said: $a[0] = "4" $a[1] = "12" $a[2] = "345" $a[3] = "678" $a[4] = "9123" array 1 and array 4 are messed up mmavipc said: that code does the exact same thing as SS which is not that i want i want $a[0] = 4 $a[1] = 123 $a[2] = 456 $a[3] = 789 $a[4] = 123 and if the string was 123456789123456789123(21 characters long) I would want it to do $a[0] = 7 $a[1] = 123 $a[2] = 456 $a[3] = 789 $a[4] = 123 $a[5] = 456 $a[6] = 789 $a[7] = 123look at the output you told me you wanted, mine outputs exactly what you said. I asked what you wanted it to look like... Easily remedied though:$sString = "123456789123" $a = _myStringFunc($sString) _ArrayDisplay($a) Func _myStringFunc($sString, $sPattern = "(...)") Local $aSRE = StringRegExp($sString, $sPattern, 3) Local $nUBound = UBound($aSRE), $avArray[$nUBound + 1], $iCC $avArray[0] = $nUBound For $iCC = 0 To $nUBound - 1 $avArray[$iCC + 1] = $aSRE[$iCC] Next Return $avArray EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Paulie Posted March 15, 2008 Posted March 15, 2008 (edited) Stringchop created by Siao#include <Array.au3> _ArrayDisplay(_StringChop("123456789123456789123",3)) Func _StringChop($string, $size) $count = Ceiling(StringLen($string)/$size) Dim $array[$count+1], $start = 1 For $i = 1 To $count $array[$i] = StringMid($string, $start, $size) $start += $size Next $array[0] = $count Return $array EndFunchttp://www.autoitscript.com/forum/index.ph...;hl=_StringChop Edited March 15, 2008 by Paulie
mmavipc Posted March 15, 2008 Author Posted March 15, 2008 Thanks Paulie [size="10"]Pure Au3 crypt funcs(I'm currently also working on making a dll from this)[/size][Y] Be more active in the community[Y] Get 200 posts[N] Get 300 posts[N] Make a Topic in the example scripts forum with at least 50 replies.People who currently hate me:ValikSmOke_N
Moderators SmOke_N Posted March 16, 2008 Moderators Posted March 16, 2008 Paulie said: Stringchop created by Siao #include <Array.au3> _ArrayDisplay(_StringChop("123456789123456789123",3)) Func _StringChop($string, $size) $count = Ceiling(StringLen($string)/$size) Dim $array[$count+1], $start = 1 For $i = 1 To $count $array[$i] = StringMid($string, $start, $size) $start += $size Next $array[0] = $count Return $array EndFuncoÝ÷ Úêå Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Paulie Posted March 16, 2008 Posted March 16, 2008 Lol @ Smoke_N apparently, some people just don't accept responses containing a StringRegExp()
Moderators SmOke_N Posted March 16, 2008 Moderators Posted March 16, 2008 Paulie said: Lol @ Smoke_Napparently, some people just don't accept responses containing a StringRegExp() Yeah, those are the ones that will always continue to defend DOS as the only proper OS 20 years from now as well. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
fxg4758 Posted October 9, 2014 Posted October 9, 2014 On 3/16/2008 at 12:05 AM, SmOke_N said: Hi all. I need to split a message in 1200 characters and i´m using the _StringChop(), but can someone tell me how i can split in 1200 characters without break a phrase with ends in (.) . Regards.
Moderators JLogan3o13 Posted October 9, 2014 Moderators Posted October 9, 2014 fxg4758, please don't necro old posts, especially after 6 years! The language has changed a lot since 2008. If you have a question, please post a new topic, include a detailed description of what you want to do, and what you have tried for yourself thus far. I guarantee you'll get much faster help. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
fxg4758 Posted October 9, 2014 Posted October 9, 2014 On 10/9/2014 at 10:37 PM, JLogan3o13 said: fxg4758, please don't necro old posts, especially after 6 years! The language has changed a lot since 2008. If you have a question, please post a new topic, include a detailed description of what you want to do, and what you have tried for yourself thus far. I guarantee you'll get much faster help. Thanks. I create a new post. Regards
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