darkjohn20 1 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 Share this post Link to post Share on other sites
darkjohn20 1 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 Share this post Link to post Share on other sites
Neno 0 Posted May 3, 2010 That is actually extremely helpful. Share this post Link to post Share on other sites
darkjohn20 1 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. Share this post Link to post Share on other sites
jchd 1,514 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) Share this post Link to post Share on other sites
darkjohn20 1 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()... Share this post Link to post Share on other sites
jchd 1,514 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) Share this post Link to post Share on other sites