Skizmata Posted July 10, 2007 Share Posted July 10, 2007 My script is an AS400 Emulator manipulator for my work. I've broken up some data from the clip board into 4 arrays. I got the blank spaces I didn't need out with StringRegExpReplace(). But some of the array fields are left blank. How do I sort through my array and kick the empty fields out. I'm new to all this and am not looking for 100 reasons my code is bad. What can I do to get those blank files out. The data I put in my clipboard is in the comment at the end. expandcollapse popup#include <Array.au3> Dim $aIngredients[1] Dim $aDescription[1] Dim $aQuantityPer[1] Dim $aUnitOfMessure[1] $aGrab = StringSplit(clipget(),@CR,1) _ArrayDisplay( $aGrab, "Top Of" ) $i = 0 $Trim = 0 while $i < $aGrab[0] $i = $i + 1 if $i = $aGrab[0] Then $Trim = 3 Else $Trim = 4 EndIf $CurrentLine = _ArrayPop($aGrab) $Dismantle = $CurrentLine $Dismantle = StringTrimleft($Dismantle,$Trim) $Dismantle = StringTrimRight($Dismantle,42) $Dismantle = StringRegExpReplace($Dismantle, " ","") _ArrayAdd($aIngredients,$Dismantle) $Dismantle = $CurrentLine $Dismantle = StringTrimLeft($Dismantle,53) $Dismantle = StringTrimRight($Dismantle,5) $Dismantle = StringRegExpReplace($Dismantle, " ","") _ArrayAdd($aQuantityPer,$Dismantle) $Dismantle = $CurrentLine $Dismantle = StringTrimLeft($Dismantle,64) $Dismantle = StringTrimRight($Dismantle,0) $Dismantle = StringRegExpReplace($Dismantle, " ","") _ArrayAdd($aUnitOfMessure,$Dismantle) WEnd _ArrayDisplay( $aIngredients, "aIngredients" ) _ArrayDisplay( $aQuantityPer, "Quantity" ) _ArrayDisplay( $aUnitOfMessure, "UOM" ) #cs 1 PP40 40 X 80 PLAIN BAG 100/R 1.000000 EA 1 LDRP 43" x 400' LD REGRIND P 34.312500 LF 1 PAR C.I. RED PRINTED INSERT 1.000000 EA 1 SDRP 42-1/2" X 650' SMALL DI 30.570150 LF 1 PTHL1 M30T TEXTURED POLYESTER 881.150000 FT 1 PTH1 50/2 MIDD SPUN POLYESTE 2705.470000 FT 1 HCP 44" x 250' HIGH CAPACIT 91.847700 LF 1 LDP 43" x 400' LARGE DIAMON 64.876550 LF 1 MMP 43" X 600' MINI MESH EX 30.564050 LF 1 PWHT 3" X 6" WHITE TAG 1.000000 EA 1 PCLIP ALUMINUM CLIPS FOR TAGS 1.000000 EA #ce Thanks for your help! AutoIt changed my life. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 10, 2007 Share Posted July 10, 2007 (edited) Consider a test like this: If StringStripWS($Dismantle, 8) = "" Then ContinueLoopoÝ÷ Øýz-²êÞ«yìZrÙrÊ°j{m¡Ú-+-zË[ºÛajÜ"ZÞÞjYp+^²y©Ý¶§±ç¢~Ø^íý±©ò¶§«ZY^~Ò'i×b¶*'JÚâ®*VKMú+&j{e{|"X¶¸¡ù^iا©Ý¶¶¢)àÂzÊZqè¶ßÛ0«míý¶¸¦ßÜ(®H¬~Äv+Gz··öƬZ¶ë"®)à2'ZÔ®)àJÚâ¥d¡Ú-êZ®È§«¢+Ø¥¹±Õ±ÐíÉÉä¹ÔÌÐì((ìMÐÕÀÍÑÉÑ¥¹½¹¥Ñ¥½¸¥¸±¥Á½Éè) ±¥ÁAÕÐ ÌäìÄA@ÐÀÐÀ`àÀA1%8 ÄÀÀ½HĸÀÀÀÀÀÀÌäìµÀì I1µÀì|($$ÌäìÄ1I@ÐÌÅÕ½ÐìàÐÀÀÌäìÌäì1II%9@ÌиÌÄÈÔÀÀ1ÌäìµÀì I1µÀì|($$ÌäìÄAH¹$¸IAI%9Q%9MIPĸÀÀÀÀÀÀÌäìµÀì I1µÀì|($$ÌäìÄMI@ÐȴļÈÅÕ½Ðì`ØÔÀÌäìÌäìM510$ÌÀ¸ÔÜÀÄÔÀ1ÌäìµÀì I1µÀì|($$ÌäìÄAQ!0Ä4ÌÁPQaQUIA=1eMQHààĸÄÔÀÀÀÀPÌäìµÀì I1µÀì|($$ÌäìÄAQ ÄÔÀ¼È5%MAU8A=1eMQÈÜÀÔ¸ÐÜÀÀÀÀPÌäìµÀì I1µÀì|($$ÌäìÄ! @ÐÐÅÕ½ÐìàÈÔÀÌäìÌäì!% A %PäĸàÐÜÜÀÀ1ÌäìµÀì I1µÀì|($$ÌäìÄ1@ÐÌÅÕ½ÐìàÐÀÀÌäìÌäì1I%5=8ØиàÜØÔÔÀ1ÌäìµÀì I1µÀì|($$ÌäìÄ55@ÐÌÅÕ½Ðì`ØÀÀÌäìÌäì5%9$5M `ÌÀ¸ÔØÐÀÔÀ1ÌäìµÀì I1µÀì|($$ÌäìÄA]!PÌÅÕ½Ðì`ØÅÕ½Ðì]!%QQĸÀÀÀÀÀÀÌäìµÀì I1µÀì|($$ÌäìÄA 1%@1U5%9U4 1%AL=HQLĸÀÀÀÀÀÀÌäìµÀì I1µÀì|($$ÌäìÌäìµÀì I1µÀì|($$ÌäìÌäìµÀì I1µÀì|($$ÌäìÌäì¤()¥´ÀÌØí%¹É¥¹ÑÍlÅt)¥´ÀÌØíÍÉ¥ÁÑ¥½¹lÅt)¥´ÀÌØíEչѥÑåAÉlÅt)¥´ÀÌØíU¹¥Ñ=5ÍÍÕÉlÅt((ÀÌØíÉôMÑÉ¥¹MÁ±¥Ð¡ ±¥ÁÐ ¤° I1°Ä¤)}ÉÉå¥ÍÁ±ä ÀÌØíÉ°ÅÕ½ÐíQ½À=ÅÕ½Ðì¤()½ÈÀÌØí¤ôÄQ¼ÀÌØíÉlÁt(%%MÑÉ¥¹MÑÉ¥Á]L ÀÌØíÉlÀÌØí¥t°à¤ôÌäìÌäìQ¡¸($% ½¹Ñ¥¹Õ1½½À(%±Í($$ÀÌØí¥Íµ¹Ñ±ôMÑÉ¥¹MÑÉ¥Á]L¡MÑÉ¥¹5¥ ÀÌØíÉlÀÌØí¥t°Ð°ÈÀ¤°Ì¤($%}ÉÉå ÀÌØí%¹É¥¹ÑÌ°ÀÌØí¥Íµ¹Ñ±¤(($$ÀÌØí¥Íµ¹Ñ±ôMÑÉ¥¹MÑÉ¥Á]L¡MÑÉ¥¹5¥ ÀÌØíÉlÀÌØí¥t°ÈÜ°ÈФ°Ì¤($%}ÉÉå ÀÌØíÍÉ¥ÁÑ¥½¸°ÀÌØí¥Íµ¹Ñ±¤($$($$ÀÌØí¥Íµ¹Ñ±ôMÑÉ¥¹MÑÉ¥Á]L¡MÑÉ¥¹5¥ ÀÌØíÉlÀÌØí¥t°ÔÈ°ÄȤ°Ì¤($%}ÉÉå ÀÌØíEչѥÑåAÈ°ÀÌØí¥Íµ¹Ñ±¤(($$ÀÌØí¥Íµ¹Ñ±ôMÑÉ¥¹MÑÉ¥Á]L¡MÑÉ¥¹5¥ ÀÌØíÉlÀÌØí¥t°Ø԰̤°Ì¤($%}ÉÉå ÀÌØíU¹¥Ñ=5ÍÍÕÉ°ÀÌØí¥Íµ¹Ñ±¤(%¹%)9áÐ(ÀÌØí%¹É¥¹ÑÍlÁtôU ½Õ¹ ÀÌØí%¹É¥¹Ñ̤´Ä(ÀÌØíÍÉ¥ÁÑ¥½¹lÁtôU ½Õ¹ ÀÌØíÍÉ¥ÁÑ¥½¸¤´Ä(ÀÌØíEչѥÑåAÉlÁtôU ½Õ¹ ÀÌØíEչѥÑåAȤ´Ä(ÀÌØíU¹¥Ñ=5ÍÍÕÉlÁtôU ½Õ¹ ÀÌØíU¹¥Ñ=5ÍÍÕɤ´Ä()}ÉÉå¥ÍÁ±ä ÀÌØí%¹É¥¹ÑÌ°ÅÕ½Ðí%¹É¥¹ÑÌÅÕ½Ðì¤)}ÉÉå¥ÍÁ±ä ÀÌØíÍÉ¥ÁÑ¥½¸°ÅÕ½ÐíÍÉ¥ÁÑ¥½¸ÅÕ½Ðì¤)}ÉÉå¥ÍÁ±ä ÀÌØíEչѥÑåAÈ°ÅÕ½ÐíEչѥÑäÅÕ½Ðì¤)}ÉÉå¥ÍÁ±ä ÀÌØíU¹¥Ñ=5ÍÍÕÉ°ÅÕ½ÐíU=4ÅÕ½Ðì¤ Edited July 10, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
cppman Posted July 10, 2007 Share Posted July 10, 2007 Something like this? Func GetEntryCount($avArray, $Entry = "") Local $entry_count = 0 For $i = 0 to Ubound($avArray)-1 if ($avArray[$i] <> $Entry) then $Entry_count += 1 Next return $entry_count EndFunc Func RemoveEntries($avArray) Local $avNewArray[GetEntryCount($avArray)] Local $nCurPointer = 0 for $i = 0 to Ubound($avArray)-1 if ($avArray[$i] == "") Then Else $avNewArray[$nCurPointer] = $avArray[$i] $nCurPointer += 1 EndIf Next return $avNewArray EndFuncoÝ÷ Úë")¶¬jëh×6#include <array.au3> Global $test[9] = ["Hello", "", "World", "", "This", "Is", "a", "", "Test"] $result = RemoveEntries($test) _ArrayDisplay($result) ? Miva OS Project Link to comment Share on other sites More sharing options...
Skizmata Posted July 10, 2007 Author Share Posted July 10, 2007 (edited) Thank you very much guys. I learned allot from Saltys code and applicate Chris' contribution too. Its strange to me to be on a programing related forum where people don't just endlessly flame my newbie code and actually give real help after fully reading my post. I'm shocked and impressed. Thanks again! *Edit* Posted another question but figured it out before you guys could reply! Thanks again! Edited July 10, 2007 by Skizmata AutoIt changed my life. Link to comment Share on other sites More sharing options...
Skizmata Posted October 25, 2007 Author Share Posted October 25, 2007 (edited) Revisiting of an old question I still don't really get. Why does this not work... #include <array.au3> $atest = StringSplit("Sun,Mon,,Tue,Wed,,Thu,Fri,,Sat", ",") _ArrayDisplay($atest) For $i = 1 To $atest[0] If StringLen($atest[$i]) < 1 Then _ArrayDelete($atest, $i) Next Looking for an easy way to remove lines of a particular length from an array. Edited October 25, 2007 by Skizmata AutoIt changed my life. Link to comment Share on other sites More sharing options...
randallc Posted October 25, 2007 Share Posted October 25, 2007 (edited) Hi, Start at the top; For $i = $atest[0] To 1 step -1oÝ÷ ج¶¶§u©ejëh×6; arraydeltsts.au3 #include <array.au3> $atest = StringSplit("Sun,Mon,,Tue,Wed,,Thu,Fri,,Sat", ",") _ArrayDisplay($atest) For $i = $atest[0] To 1 Step - 1 If StringLen($atest[$i]) < 1 Then _ArrayDelete($atest, $i) Next $atest[0] = UBound($atest) - 1 _ArrayDisplay($atest) Edited October 25, 2007 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 25, 2007 Share Posted October 25, 2007 Revisiting of an old question I still don't really get. Why does this not work... #include <array.au3> $atest = StringSplit("Sun,Mon,,Tue,Wed,,Thu,Fri,,Sat", ",") _ArrayDisplay($atest) For $i = 1 To $atest[0] If StringLen($atest[$i]) < 1 Then _ArrayDelete($atest, $i) Next Looking for an easy way to remove lines of a particular length from an array. Already called by randallc, but just for the verbal explanation: _ArrayDelete() changes the size of the array, so if you walk the array in the forward direction, the last element pointed to by $atest[0], or Ubound($atest)-1 might not be there anymore, and that leads to subscript out of range errors. Going backwards means you won't refer again to any element you have deleted. If you have to walk the array forward, and still delete elements, you'll need a little extra logic in the loop to change your incremented variable after deleting, or ditch For/Next and use While/WEnd or Do/Until and handle the incrementing yourself. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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