litlmike Posted December 12, 2007 Posted December 12, 2007 I am trying to get rid of any Elements in an array that contain only white spaces. But, while looping through with _ArrayDelete it causes the original Ubound to go past the number of elements. I do not have much experience using ReDim or other methods like it. I assume that there must be a way to work around this. Thanks for any help. $Multi_Cat = GUICtrlRead ($Edit2) $aMulti_Cat = StringSplit($Multi_Cat, @CR) $LastElement = UBound ($aMulti_Cat)-1 For $iCC = 0 To $LastElement If StringIsSpace ( $aMulti_Cat[$iCC] ) Then _ArrayDelete ($aMulti_Cat, $iCC) EndIf Next _ArrayPermute()_ArrayUnique()Excel.au3 UDF
Valuater Posted December 12, 2007 Posted December 12, 2007 Maybe... $Multi_Cat = GUICtrlRead($Edit2) $aMulti_Cat = StringSplit($Multi_Cat, @CR) $LastElement = UBound($aMulti_Cat) - 1 Dim $New_Array For $iCC = 0 To $LastElement If StringIsSpace($aMulti_Cat[$iCC]) Then ContinueLoop _ArrayAdd($New_Array, $aMulti_Cat[$iCC]) Next _ArrayDisplay($New_Array) ; change name..blah..blah There are alot of great functions inside array.au3.... take a look inside! 8)
Xandl Posted December 12, 2007 Posted December 12, 2007 Hello, the problem is, that if you delete one element, the number of $LastElement will be wrong, as there is one element less in the array. The solution is to turn the for loop around, and work from $LastElement to 0. ciao Xandl
aslani Posted December 12, 2007 Posted December 12, 2007 Take a look at this one I use myself. This might point you to the right direction; ; Removing dashes and white spaces $pnumber = StringSplit(StringReplace(_ArrayToString($pnumber, ","), "-", ""), ",") ; Removing dashes from Part Numbers _ArrayDelete($pnumber, 0) Hope that helps. [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version
rasim Posted December 13, 2007 Posted December 13, 2007 litlmikeOne of the variants:#include <Array.au3> $Multi_Cat = GUICtrlRead($Edit2) $aMulti_Cat = StringSplit($Multi_Cat, @CR) $LastElement = UBound ($aMulti_Cat)-1 For $iCC = $LastElement To 0 Step -1 If StringIsSpace ($aMulti_Cat[$iCC] ) Then _ArrayDelete ($aMulti_Cat, $iCC) EndIf Next _ArrayDisplay($aMulti_Cat)
litlmike Posted December 13, 2007 Author Posted December 13, 2007 Thanks for everyone's feedback. I tried all of the approaches until one finally worked. I still can't figure why Valuater's didn't work, but below is what I ended up with. The only scenario I cannot get it to work in, is if the starting elements are WhiteSpace. So it works if the Elements are like this: ['a','b','c'] or ['a','b',' '] or ['a',' ','c ']; but not if it is [' ','b',' c']. Any ideas? $LastElement = UBound ($aMulti_Cat)-1 For $iCC = $LastElement To 0 Step -1 If StringIsSpace ($aMulti_Cat[$iCC] ) Then _ArrayDelete ($aMulti_Cat, $iCC) EndIf Next _ArrayPermute()_ArrayUnique()Excel.au3 UDF
aslani Posted December 13, 2007 Posted December 13, 2007 A special UDF for you Func _CleanStringSpec(ByRef $splitstring, $dataname) $splitdata = StringSplit(StringReplace(StringReplace(_ArrayToString($splitstring, "*"), @CRLF, "*"), "-", ""), "*") ;_ArrayDelete($splitdata, 0) For $x1 = Ubound($splitdata) - 1 To 0 Step -1 If StringStripWS($splitdata[$x1], 8) = "" Then _ArrayDelete($splitdata, $x1) Next _ArrayDisplay($splitdata, "CleanStringSpec() Result - " & $dataname) EndFuncoÝ÷ ØLZ^jëh×6#Include <Array.au3> Dim $pnumber1[3] = ['a','b','c'] Dim $pnumber2[3] = ['a',' ','c'] Dim $pnumber3[3] = ['a','b',' '] Dim $pnumber4[3] = [' ','b','c'] _CleanStringSpec($pnumber4, "P4") Func _CleanStringSpec(ByRef $splitstring, $dataname) $splitdata = StringSplit(StringReplace(StringReplace(_ArrayToString($splitstring, "*"), @CRLF, "*"), "-", ""), "*") ;_ArrayDelete($splitdata, 0) For $x1 = Ubound($splitdata) - 1 To 0 Step -1 If StringStripWS($splitdata[$x1], 8) = "" Then _ArrayDelete($splitdata, $x1) Next _ArrayDisplay($splitdata, "CleanStringSpec() Result - " & $dataname) EndFunc [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version
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