USMCGalloway Posted August 21, 2013 Share Posted August 21, 2013 (edited) Local $k = 0 , $v = 1, $d = "|||", $us , $emotion, $what Local $info = "We|||Love|||autoit|||" $pairs = StringSplit($info, $d ,2) Alright my whole thread is changing, because no matter how long you look at something until you post it you will never get it. At this point I have what I wanted working to an extent. But String Split leaving weird spaces in the in the array. Any way to prevent this ? [0]|data=foo [1]| [2]| [3]|data2=bar [4]| [5]| [6]|data3=hippie [7]| [8]| [9]| Edited August 21, 2013 by USMCGalloway Link to comment Share on other sites More sharing options...
0xdefea7 Posted August 21, 2013 Share Posted August 21, 2013 You need to subtract 1 from your Ubound, and 'Step 1' is implied: for $i = 0 To UBound($pairs) - 1 Try that. Yes you can StringSplit an array element Link to comment Share on other sites More sharing options...
dragan Posted August 21, 2013 Share Posted August 21, 2013 (edited) you used: $pairs = StringSplit($info, $d ,2) but you want to split the string with string delimiter, and if you still want to disable return of item count as first element you would have to use this: $pairs = StringSplit($info, $d ,2+1) And finally, you would have to use this: for $i = 0 To UBound($pairs)-1 ;instead of for $i = 0 To UBound($pairs) step 1 because of the zero-index counting. EDIT: You have changed your first post, but did you even look at the explanation I gave you? Edited August 21, 2013 by dragan Link to comment Share on other sites More sharing options...
kylomas Posted August 21, 2013 Share Posted August 21, 2013 USMCGalloway, It is in your benefit to leave posts in tact as originally written and amend info using notation such as "edit: - " followed by change/explanation. This avoids confusion for anyone following the thread who may be able to help. You may also refer back to this thread in the future and forget what you changed. 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 Link to comment Share on other sites More sharing options...
Malkey Posted August 21, 2013 Share Posted August 21, 2013 Local $k = 0 , $v = 1, $d = "|||", $us , $emotion, $what Local $info = "We|||Love|||autoit|||" $pairs = StringSplit($info, $d ,2) Alright my whole thread is changing, because no matter how long you look at something until you post it you will never get it. At this point I have what I wanted working to an extent. But String Split leaving weird spaces in the in the array. Any way to prevent this ? [0]|data=foo [1]| [2]| [3]|data2=bar [4]| [5]| [6]|data3=hippie [7]| [8]| [9]| Run this example and see comments in this example. #include <Array.au3> ; For _ArrayDisplay purposes only Local $d = "|||" Local $info = "We|||Love|||autoit|||" If StringRight($info, StringLen($d)) = $d Then $info = StringTrimRight($info, StringLen($d)) ; Remove trailing $d if present. If StringLeft($info, StringLen($d)) = $d Then $info = StringTrimLeft($info, StringLen($d)) ; Remove leading $d if present. ; See StringSplit function parameter "flag" ; flag = 1, entire delimiter string is needed to mark the split ; flag = 2, disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ; (flag 1 + flag 2 = flag 3) Local $aPairs = StringSplit($info, $d, 3) ; flag 3 _ArrayDisplay($aPairs) Link to comment Share on other sites More sharing options...
0xdefea7 Posted August 22, 2013 Share Posted August 22, 2013 If $pairs[$i] = "" Then ContinueLoop In your for loop at the top of it. Local $d = "|||" Local $info = "We|||Love|||autoit|||" $pairs = StringSplit($info, $d , 2) For $i = 0 To UBound($pairs) - 1 If $pairs[$i] = "" Then ContinueLoop ConsoleWrite($pairs[$i] & @CRLF) Next Link to comment Share on other sites More sharing options...
Malkey Posted August 22, 2013 Share Posted August 22, 2013 (edited) If $pairs[$i] = "" Then ContinueLoopIn your for loop at the top of it.Local $d = "|||" Local $info = "We|||Love|||autoit|||" $pairs = StringSplit($info, $d , 2) For $i = 0 To UBound($pairs) - 1 If $pairs[$i] = "" Then ContinueLoop ConsoleWrite($pairs[$i] & @CRLF) Next If you put a hole in a bucket only so that you can fix it , then here is another fix.Local $d = "|||" Local $info = "We|||Love|||autoit|||" $pairs = StringSplit($info, $d, 2) For $i = 0 To UBound($pairs) - 2 Step Stringlen($d) ConsoleWrite($pairs[$i] & @CRLF) NextEdit: Changed "Step 3"To"Step Stringlen($d)"alluding to the fact that the flag 2 parameter of the StringSplit function is the cause of all the extra blank elements added to the resultant array. Edited August 22, 2013 by Malkey 0xdefea7 1 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