Realm 18 Posted April 22, 2010 How Do I check to for an Array size, Lets say I need to check a string to see if it has 6 or 7 elements, and than if it has 6 elements, How do I add an element in the proper spot, lets say element3 7 elements string "Item,value1,value2,category1,category2,edition,number,binary(yes/no)" should pass as ok 6 element string "Item,value1,value2,category2,edition,number,binary(yes/no)" need to add Category1 in the correct element location Help is appreciated. Thanks ahead of time! My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Share this post Link to post Share on other sites
enaiman 16 Posted April 22, 2010 UBound _ArrayAdd SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example scriptwannabe "Unbeatable" Tic-Tac-ToePaper-Scissor-Rock ... try to beat it anyway :) Share this post Link to post Share on other sites
Malkey 231 Posted April 22, 2010 Here are two different examples with the same inputs and similar outputs. Array method:- #include <Array.au3> Local $string = "Item,value1,value2,category2,edition,number,binary(yes/no)" Local $sStrInsert = "category1" Local $iInsertAfterPos = 3 Local $sNewstring Local $aArray = StringSplit($string, ",", 2) ; flag = 2, disable the return the count in the first element ConsoleWrite("Number of elements in array = " & UBound($aArray) & @CRLF) _ArrayInsert($aArray, $iInsertAfterPos, $sStrInsert) ConsoleWrite("Number of elements in new array = " & UBound($aArray) & @CRLF) _ArrayDisplay($aArray) ; Back to string For $i = 0 To UBound($aArray) - 1 $sNewstring &= $aArray[$i] & "," Next ConsoleWrite('New string is "' & StringTrimRight($sNewstring, 1) & '"' & @CRLF) String method:- Local $string = "Item,value1,value2,category2,edition,number,binary(yes/no)" Local $sStrInsert = "category1" Local $iInsertAfterPos = 3 Local $sNewString, $iNumElements, $iNumNewElements StringReplace($string, ",", ",") $iNumElements = @extended + 1 ConsoleWrite("Number of comma separated elements in string = " & $iNumElements & @CRLF) If $iInsertAfterPos >= $iNumElements Then $sNewString = $string & "," & $sStrInsert Else $sNewString = StringRegExpReplace($string, "((?:.+?,){" & $iInsertAfterPos & "})(.*){:content:}quot;, "${1}" & $sStrInsert & ",${2}") EndIf StringReplace($sNewString, ",", ",") $iNumNewElements = @extended + 1 ConsoleWrite("Number of comma separated elements in new string = " & $iNumNewElements & @CRLF) ConsoleWrite('New string is "' & $sNewString & '"' & @CRLF) Share this post Link to post Share on other sites
Realm 18 Posted April 23, 2010 (edited) Thanks a lot for your quick replies. Was not what I was looking for, but I enjoyed the material to learn from. Thanks again! I have found the solution thanks to another member of the board! Edited April 23, 2010 by Realm My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Share this post Link to post Share on other sites
JohnOne 1,603 Posted April 23, 2010 (edited) Hi Realm I was reading this thread with interest, but found that Malkeys example done exactly what you asked. I wonder if you can help me out and link me to the thread that gave you your solution. Thanks. Edited April 23, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Share this post Link to post Share on other sites
Realm 18 Posted April 23, 2010 Hi RealmI was reading this thread with interest, but found that Malkeys example done exactly what you asked.I wonder if you can help me out and link me to the thread that gave you your solution.Thanks.I quoted that wrong, my appologies. His suggestion was great, and I shall learn from it. But I ended up with a couple more problems after using those suggestions, not that they were wrong, but my csv and ini lists had more obstacles. Another forum member helped me to come to an ultimate solution. Sorry for wording my last quote wrong. My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Share this post Link to post Share on other sites