18 posts in this topic
Problems with arrays
In my current project I have a part that should convert from string to array, and later on that array should be converted to a string again.
The first part works just fine and I get the array just as I want it, but on the way back I'm encountering some issues...
Func Encode($data0) ; works just fine, just here for clarification. ; That if-statement in the middle is just there that I'm always getting a string with 5 symbols ; $data0 = "A" in this example Local $data1 = "" Local $tmp = "" Local $arr = StringSplit($data0, "", 2) For $i = 0 To UBound($arr)-1 $tmp = AscW($arr[$i]) If $tmp = 0 Then $tmp = "00000" & $tmp ElseIf $tmp > 0 And $tmp < 10 Then $tmp = "0000" & $tmp ElseIf $tmp >= 10 And $tmp < 100 Then $tmp = "000" & $tmp ElseIf $tmp >= 100 And $tmp < 1000 Then $tmp = "00" & $tmp ElseIf $tmp >= 1000 And $tmp < 10000 Then $tmp = "0" & $tmp ElseIf $tmp >= 10000 And $tmp <= 65535 Then $tmp = $tmp EndIf $data1 = $data1 & $tmp Next Return $data1 EndFunc Func Decode($data0) ; does NOT work ; $data0 = "00065" ; via MsgBox and ConsoleWrite I could find out that it fails already before StringSplit ; when it fails, no message is given and everything just disappears Local $data1 = "" Local $tmp = "" Local $arr = StringSplit(String($data0), "", 2) For $i = 0 To UBound($arr)-1 Step 5 $tmp = $arr[$i] & $arr[$i+1] & $arr[$i+2] & $arr[$i+3] & $arr[$i+4] & $arr[$i+5] $tmp = ChrW($tmp) $data1 = $data1 & $tmp Next Return $data1 EndFunc Sorry for dropping all the #include, the GUI, the login screen, etc... It's not necessary for this problem and I needn't give you a 613kB file full of plain text for finding an error in 3 lines of code.
I found out that $arr is always empty, so there must be an issue with StringSplit. I suspected "00065" might be seen as an integer and converted it to a string, but that doesn't make it work. I already played around quite a while with that issue now, I hope some of you can finally relieve me.
BIG String to Array
I am getting the "RawData" return from FastFind's "FFGetRawData" function and then attempting to make it into an array.
What I have here does the job as it should but it is a slow process. I feel I may be overlooking a more effecient way to handle this matter. In the end ( in an ideal situation ) I'd like to end up with a 2D array with 580 col and 375 rows. Currently it's just a 1D array as I am still trying to get my head around how to make it into a 2D. BUT... My question is this ...
Is there a better way to handle what I am trying to do?
Func trimmer () Local $i = 0 ;The "Counter" Local $WorkAreaLength = StringLen ($WorkAreaData) ;Get the length of the string ConsoleWrite ("WorkAreaLegnth="&$WorkAreaLength&@CR) Local $iWorkAreaLengthCount = $WorkAreaLength / 8 ;How many segments of 8 can we make? Use this for the counter later on ConsoleWrite ("WorkArealengthCount="&$iWorkAreaLengthCount&@CR) Local $sPiece = 0 ; The string segment holder Global $aWorkArea ; The array to write to Do $sPiece = StringLeft ($WorkAreaData, 8) ; Grab the first 8 characters and put them into $sPiece _ArrayAdd ($aWorkArea, $sPiece) ; Put what $sPiece is into the array StringTrimLeft ($WorkAreaData, 8) ;Trim off the first 8 characters that were just copied $i = $i + 1 ;Count up 1 ConsoleWrite ($i&@CR) Until $i >= $iWorkAreaLengthCount ; Keep going until $i >= $iWorkAreaLengthCount ConsoleWrite ("Done"&@CR) Local $sFile = FileOpen ("main.txt");Open the text file _FileWriteFromArray ($sFile , $aWorkArea);Write the array to the text file FileClose ($sFile); Close the text file EndFunc
A little secondary problem, that isn't throwing any errors to speak of, is the file is never written to. It remains blank even though it is in the same directory as the script and the script isn't responding with any errors. This isn't my main focus though as it just lets me see what the array is rather than using the console which can be a little cramped at times.
Any advise would be appreciated, thank you!
Why can't we append Null to a string?
Here is some code:
ConsoleWrite("Test" == "Test" & Null) ; This should be False by theory, but it is True in AutoIt Sleep(1000) ; Sometime for you to read the result
Is this a bug or expected behaviour? Thanks in Advance, TD
Help with splitting a complex string
Hello , I am trying to find the best way to spilt this string:
:<nick>!<host mask> PRIVMSG <channel/nick> :<message> into an array like this:
Global Enum $SENT_BY, $HOST_MASK, $SENT_TO, $MESSAGE $aArray[$SENT_BY] = "<nick>" $aArray[$HOST_MASK] = "<host mask>" $aArray[$SENT_TO] = "<channel/nick>" $aArray[$MESSAGE] = "<message>" (Stuff between <> is dynamic)
I can do that with inefficient code but I think it is possible to do it more efficiently with RegEx
Thanks in Advance! TD
P.S Yeah, that is the raw format of a message received in IRC
How to split String in Autoit
I need you help in splitting a string, but the main problem is I can't say a perfect way how that starts and stops.... check this sample.
The above is the input data I want the autoit to split it like this
I have put a ";" where I need the data to be splitted. plzz help me out in any way, any symbol, any code. Plzz guys.