By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,239 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,239 IT Pros & Developers. It's quick & easy.

Finding a pattern in a stream?

P: n/a
Is there a good way to find a pattern of bytes/chars in a stream? I've got
a serial port connected to a tcp port. I need to be able to catch a unique
character string in the stream so that I can perform certain functions. For
example, I have a telnet client connected to an Apple II through the serial
port. The user at the telnet terminal is using the BBS running on the Apple
II just like the good ole days of dialup BBS's. I need to be able to catch
a "command string" sent out from the Apple II (like the "+++ATH") that tells
my app to disconnect the telnet client (in lieu of the modem hanging up).
Is there a good way to do this?
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi,

Regular expression are the best way to find patterns.
http://msdn.microsoft.com/library/de...xpressions.asp

Ken
-----------------------------
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Is there a good way to find a pattern of bytes/chars in a stream? I've got
a serial port connected to a tcp port. I need to be able to catch a unique
character string in the stream so that I can perform certain functions. For
example, I have a telnet client connected to an Apple II through the serial
port. The user at the telnet terminal is using the BBS running on the Apple
II just like the good ole days of dialup BBS's. I need to be able to catch
a "command string" sent out from the Apple II (like the "+++ATH") that tells
my app to disconnect the telnet client (in lieu of the modem hanging up).
Is there a good way to do this?

Nov 21 '05 #2

P: n/a
Just doing a quick read of the page it looks as though Regex functions
similarly to the InStr() function. Is Regex actually faster and more
efficient than using InStr?

Also, how would I find my pattern if it is broken up into two "reads"? For
example, I wait for a DataArrival event, read from the serial port and pass
the data out the TCP port. Say the string i'm looking for is "+++ATH". So
I read the serial port and receive "<other data>+++A" and then on the next
read of the serial port I get "TH<more data>". Or maybe it could
conceivably be broken up into 3 or more reads. Is this a situation where I
just have to concatenate the current read with the previous read and then
look for the pattern? Or is there a better way?

Thanks for the help.
Terry

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
Hi,

Regular expression are the best way to find patterns.
http://msdn.microsoft.com/library/de...xpressions.asp

Ken
-----------------------------
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Is there a good way to find a pattern of bytes/chars in a stream? I've
got
a serial port connected to a tcp port. I need to be able to catch a
unique
character string in the stream so that I can perform certain functions.
For
example, I have a telnet client connected to an Apple II through the
serial
port. The user at the telnet terminal is using the BBS running on the
Apple
II just like the good ole days of dialup BBS's. I need to be able to
catch
a "command string" sent out from the Apple II (like the "+++ATH") that
tells
my app to disconnect the telnet client (in lieu of the modem hanging up).
Is there a good way to do this?

Nov 21 '05 #3

P: n/a
Terry,
You would need to check each read to see if it contains the characters you
are looking for. Be careful, depending on how you defined the "Read" your
characters may be spread across two reads.
InStr allows you to find a fixed set of characters a "word".

RegEx allows you to find a pattern (a variable set of characters), the Like
operator is a simplified form of RegEx.

For example: The "^\d+$" RegEx pattern says to find the beginning of the
line/string "^" followed by one or more "+" digits "\d", followed by the end
of the line/string "$"
A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp
Hope this helps
Jay

"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Just doing a quick read of the page it looks as though Regex functions
similarly to the InStr() function. Is Regex actually faster and more
efficient than using InStr?

Also, how would I find my pattern if it is broken up into two "reads"?
For example, I wait for a DataArrival event, read from the serial port and
pass the data out the TCP port. Say the string i'm looking for is
"+++ATH". So I read the serial port and receive "<other data>+++A" and
then on the next read of the serial port I get "TH<more data>". Or maybe
it could conceivably be broken up into 3 or more reads. Is this a
situation where I just have to concatenate the current read with the
previous read and then look for the pattern? Or is there a better way?

Thanks for the help.
Terry

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
Hi,

Regular expression are the best way to find patterns.
http://msdn.microsoft.com/library/de...xpressions.asp

Ken
-----------------------------
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Is there a good way to find a pattern of bytes/chars in a stream? I've
got
a serial port connected to a tcp port. I need to be able to catch a
unique
character string in the stream so that I can perform certain functions.
For
example, I have a telnet client connected to an Apple II through the
serial
port. The user at the telnet terminal is using the BBS running on the
Apple
II just like the good ole days of dialup BBS's. I need to be able to
catch
a "command string" sent out from the Apple II (like the "+++ATH") that
tells
my app to disconnect the telnet client (in lieu of the modem hanging up).
Is there a good way to do this?


Nov 21 '05 #4

P: n/a
Yeah, that was my question in the post. What if my characters ARE spread
across two reads? Do I need to concatenate the previous read with the
current read and check for the pattern? Or is there another way?
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ua*************@TK2MSFTNGP11.phx.gbl...
Terry,
You would need to check each read to see if it contains the characters you
are looking for. Be careful, depending on how you defined the "Read" your
characters may be spread across two reads.
InStr allows you to find a fixed set of characters a "word".

RegEx allows you to find a pattern (a variable set of characters), the
Like operator is a simplified form of RegEx.

For example: The "^\d+$" RegEx pattern says to find the beginning of the
line/string "^" followed by one or more "+" digits "\d", followed by the
end of the line/string "$"
A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp
Hope this helps
Jay

"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Just doing a quick read of the page it looks as though Regex functions
similarly to the InStr() function. Is Regex actually faster and more
efficient than using InStr?

Also, how would I find my pattern if it is broken up into two "reads"?
For example, I wait for a DataArrival event, read from the serial port
and pass the data out the TCP port. Say the string i'm looking for is
"+++ATH". So I read the serial port and receive "<other data>+++A" and
then on the next read of the serial port I get "TH<more data>". Or maybe
it could conceivably be broken up into 3 or more reads. Is this a
situation where I just have to concatenate the current read with the
previous read and then look for the pattern? Or is there a better way?

Thanks for the help.
Terry

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
Hi,

Regular expression are the best way to find patterns.
http://msdn.microsoft.com/library/de...xpressions.asp

Ken
-----------------------------
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Is there a good way to find a pattern of bytes/chars in a stream? I've
got
a serial port connected to a tcp port. I need to be able to catch a
unique
character string in the stream so that I can perform certain functions.
For
example, I have a telnet client connected to an Apple II through the
serial
port. The user at the telnet terminal is using the BBS running on the
Apple
II just like the good ole days of dialup BBS's. I need to be able to
catch
a "command string" sent out from the Apple II (like the "+++ATH") that
tells
my app to disconnect the telnet client (in lieu of the modem hanging
up).
Is there a good way to do this?



Nov 21 '05 #5

P: n/a
Terry,
You could concatenate the two reads together, or match as much as the
pattern in the first read, remember how much you did match, then match the
rest in the second read.

I would recommend which ever you understand & are the most comfortable with.
Concatenating the two reads obviously will be easier... Where as depending
on what else you are doing (you already have a "parser") the second might be
easy enough to have the parser just handle...

Hope this helps
Jay

"Terry Olsen" <to******@hotmail.com> wrote in message
news:eJ**************@TK2MSFTNGP11.phx.gbl...
Yeah, that was my question in the post. What if my characters ARE spread
across two reads? Do I need to concatenate the previous read with the
current read and check for the pattern? Or is there another way?
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ua*************@TK2MSFTNGP11.phx.gbl...
Terry,
You would need to check each read to see if it contains the characters
you are looking for. Be careful, depending on how you defined the "Read"
your characters may be spread across two reads.
InStr allows you to find a fixed set of characters a "word".

RegEx allows you to find a pattern (a variable set of characters), the
Like operator is a simplified form of RegEx.

For example: The "^\d+$" RegEx pattern says to find the beginning of the
line/string "^" followed by one or more "+" digits "\d", followed by the
end of the line/string "$"
A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp
Hope this helps
Jay

"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Just doing a quick read of the page it looks as though Regex functions
similarly to the InStr() function. Is Regex actually faster and more
efficient than using InStr?

Also, how would I find my pattern if it is broken up into two "reads"?
For example, I wait for a DataArrival event, read from the serial port
and pass the data out the TCP port. Say the string i'm looking for is
"+++ATH". So I read the serial port and receive "<other data>+++A" and
then on the next read of the serial port I get "TH<more data>". Or
maybe it could conceivably be broken up into 3 or more reads. Is this a
situation where I just have to concatenate the current read with the
previous read and then look for the pattern? Or is there a better way?

Thanks for the help.
Terry

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
Hi,

Regular expression are the best way to find patterns.
http://msdn.microsoft.com/library/de...xpressions.asp

Ken
-----------------------------
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Is there a good way to find a pattern of bytes/chars in a stream? I've
got
a serial port connected to a tcp port. I need to be able to catch a
unique
character string in the stream so that I can perform certain functions.
For
example, I have a telnet client connected to an Apple II through the
serial
port. The user at the telnet terminal is using the BBS running on the
Apple
II just like the good ole days of dialup BBS's. I need to be able to
catch
a "command string" sent out from the Apple II (like the "+++ATH") that
tells
my app to disconnect the telnet client (in lieu of the modem hanging
up).
Is there a good way to do this?




Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.