Adolfik Posted July 22, 2010 Share Posted July 22, 2010 Hi everyone So I got a specific data string which looks like 0041002137293/66840/1279759439/1279494808/370248530/1/0/5/1544/... It's much much longer, but what I'd like to get of it is: 1:0041002137293 2:66840 3:1279759439 4:..... 5:..... 6:1 7:0 and so on Great thanks Link to comment Share on other sites More sharing options...
ALTIN Posted July 22, 2010 Share Posted July 22, 2010 So easy, you just needed to read help file and would have find StringSplit() function This is what you need: $stringData = Stringsplit("0041002137293/66840/1279759439/1279494808/370248530/1/0/5/1544", "/", 1) For $i = 1 to $StringData[0] Msgbox (0, "", $StringData[$i]) Next Link to comment Share on other sites More sharing options...
Adolfik Posted July 22, 2010 Author Share Posted July 22, 2010 Big thanks! I did some changes and it works in a simple script $text =fileread("data.txt") ;read textfile $test = StringSplit($text,"/", 1) Msgbox (0, "data","thing1: " & $test[8] & " thing2 " & $test[9]&"/"&$test[10]&" thing3: " &$test[14]&" thing4: "&$test[15]) but when I try to put it into a script with loop it gives me error ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: I don't want it to display all the info from data.txt but just just few essential values Here is a part of script I use If $zdata<>Binary("") Then $test = StringSplit((BinaryToString ($zdata)) ,"/", 1) Msgbox (0, "hello","info: " & $test[8] & " info " & $test[9]&"/"&$test[10]&" info: " &$test[14]&" info: "&$test[15]) $timeout=TimerInit(); got data reset timeout timer TCPSend($sock,$zdata) EndIf It fails on msgbox.... and anywhere else where I want to use these values(it is displayed but script fails right after) Link to comment Share on other sites More sharing options...
enaiman Posted July 23, 2010 Share Posted July 23, 2010 Read what StringSplit is doing (SciTe - F1, and look for StringSplit) You will see that the output is an array - once you reference "non-existing" members of that array you get the same error. Answer your $test[14] or $test[15] might not exist = the string does not have so many groups. Solution: see how many elements the array has and whatever you do, do not go over the number of elements. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
ALTIN Posted July 23, 2010 Share Posted July 23, 2010 (edited) It fails on msgbox.... and anywhere else where I want to use these values(it is displayed but script fails right after) As enaiman said you get the above error when you refer to an index that doesn't exist. For example if StringSplit() returned an array with 5 elements and you want to get lets say $test[9] you get the above error. Just make sure to use correct indexes, and keep in mind that the data in the file you read may change (i think) and these indexes may change too. I'm not very clear about what do you want to do with this, however I think you got the idea in what you need to correct.... Edited July 23, 2010 by ALTIN Link to comment Share on other sites More sharing options...
Adolfik Posted July 23, 2010 Author Share Posted July 23, 2010 Thanks for answers I will ask another question (I hope it's the last one) so is there any way to stop whole script to terminate when this error occurs? or maybe I can somehow check how long received string is, and just do nothing when it's too short. If $zdata<>Binary("") Then $test = StringSplit((BinaryToString ($zdata)) ,"/", 1) $timeout=TimerInit(); got data reset timeout timer TCPSend($sock,$zdata) sth like If $test got more than 15 values then Msgbox (0, "hello","info: " & $test[8] & " info " & $test[9] & "/" & $test[10] & " info: " & $test[14] & " info: " & $test[15]) if else msgbox(0,"error","error") EndIf Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 23, 2010 Moderators Share Posted July 23, 2010 Adolfik, maybe I can somehow check how long received string isIf you look at StringSplit in the Help file, you will see that the [0] element of the returned array contains the count of the returned strings - so it is easy to see if you have enough to fill your MsgBox. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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