darkjohn20 Posted May 3, 2010 Share Posted May 3, 2010 (edited) Hi, I'm working on a TCP Client and Server, and in order to eliminate Sleeping in between send commands, I've decided to add a terminator to each thing I send. (Thanks Kip) My problem is, each command is one of these formats: Hex($Code)|$Additional_Information~ Hex($Code)~ Example: 00000001|Hello?~ 000000FF~ Where "~" is the terminator and "|" is just a split to know when the code ends and the information starts. My question is, how can I easily separate multiple commands using the terminator, and then the split? An example being: 00FA001E~0000CC01|Test String!@~00A0BBC0~ Where it should be split first like this: 00FA001E 0000CC01|Test String!@ 00A0BBC0 and then those with additional information like this: 0000CC01 Test String!@ I was thinking maybe a StringSplit using the "~" and then the "|" but that seemed kind of messy. Also, as a side note, the additional info parameter can include ANYTHING but the terminator. It is not limited to alpha-numeric. Edited May 3, 2010 by darkjohn20 Link to comment Share on other sites More sharing options...
darkjohn20 Posted May 3, 2010 Author Share Posted May 3, 2010 I think it took more time writing that out then figuring out how to do it... Anyways, I figured it out. Here it is: Func _InfoReceived($hSocket, $sReceived, $iError) $Received = StringSplit($sReceived, $sTerminator) For $X = 1 To $Received[0] If $Received[$X] <> "" Then If Not StringInStr($Received[$X], "|") Then ;Code Only _EvaluateCode($Received[$X], $hSocket, $iError) Else ;Code and Information $Information = StringSplit($Received[$X], "|") _EvaluateCodeEx($Information[1], $Information[2], $hSocket, $iError) EndIf EndIf Next EndFunc Link to comment Share on other sites More sharing options...
Neno Posted May 3, 2010 Share Posted May 3, 2010 That is actually extremely helpful. Link to comment Share on other sites More sharing options...
darkjohn20 Posted May 3, 2010 Author Share Posted May 3, 2010 That is actually extremely helpful. I figured since I made the post I might as well post my solution for others. Link to comment Share on other sites More sharing options...
jchd Posted May 3, 2010 Share Posted May 3, 2010 I'm curious: why do you need the | separator at all, since I assume the hex code is fixed length? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
darkjohn20 Posted May 3, 2010 Author Share Posted May 3, 2010 True. I don't know. I like separators even if they aren't the cleanest method. Maybe I'll switch over to StringTrimLeft()... Link to comment Share on other sites More sharing options...
jchd Posted May 3, 2010 Share Posted May 3, 2010 That, or simply a single regexp to split things apart. It would simplify your life greatly if _EvaluateCodeEx() would accept an empty second argument and behave as _EvaluateCode(). This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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