469,936 Members | 2,466 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,936 developers. It's quick & easy.

Parsing a string

Can someone show me how to parse a string to find a specific value?

<b><a id="wt2500_WC_xc2500_GVB_drtl00_WQR_xt400_G"
href="/WW/XZ/LinkToDetailsList.asp">Details List Filers</a></b>

That is my string, I have thousands of lines to go through, I am looking to
get back the
following value: "Details List Filers"

These are unique in the string:

String Begin: <b><a id="
String End: </a></b>

Once I find my string that starts with the begin sequence, I need to parse
the rest of the string to get the
value that I want. To be honest I don't have a clue what to do, can someone
provide a small example
that will get me started.
Appreciate the help.
John-
Feb 4 '08 #1
6 1481
try using regular expression to get list of matching strings
try something like <b><a id=.*>(?<innerText>.*)</a></b>
Regex oRE= new Regex("<b><a id=.*>(?<innerText>.*)</a></b>");
String s = "<b><a id=\"wt2500_WC_xc2500_GVB_drtl00_WQR_xt400_G\"
href=\"/WW/XZ/LinkToDetailsList.asp\">Details List Filers</a></b>";
Match m = oRE.Match(s);
if ( m.Success )
Console.WriteLine("User: " + m.Groups["innerText"].Value);
--
Misbah Arefin
"John Rogers" <jo************@aol.comwrote in message
news:Ol*************@TK2MSFTNGP02.phx.gbl...
Can someone show me how to parse a string to find a specific value?

<b><a id="wt2500_WC_xc2500_GVB_drtl00_WQR_xt400_G"
href="/WW/XZ/LinkToDetailsList.asp">Details List Filers</a></b>

That is my string, I have thousands of lines to go through, I am looking
to get back the
following value: "Details List Filers"

These are unique in the string:

String Begin: <b><a id="
String End: </a></b>

Once I find my string that starts with the begin sequence, I need to parse
the rest of the string to get the
value that I want. To be honest I don't have a clue what to do, can
someone provide a small example
that will get me started.
Appreciate the help.
John-

Feb 4 '08 #2
John Rogers wrote:
Can someone show me how to parse a string to find a specific value?

<b><a id="wt2500_WC_xc2500_GVB_drtl00_WQR_xt400_G"
href="/WW/XZ/LinkToDetailsList.asp">Details List Filers</a></b>

That is my string, I have thousands of lines to go through, I am looking to
get back the
following value: "Details List Filers"

These are unique in the string:

String Begin: <b><a id="
String End: </a></b>

Once I find my string that starts with the begin sequence, I need to parse
the rest of the string to get the
value that I want. To be honest I don't have a clue what to do, can someone
provide a small example
that will get me started.
What about a regex ?

Something like:

"(?:<b><a id=[^>]*>)([^<]*)(?:</a></b>)"

Arne
Feb 4 '08 #3
Appreciate the response guys, I didn't try to use regex because its not that
easy to use.

I have been looking at some code like SubString() and stuff like that, it
seems easier
to work with.

Which is faster when parsing strings? Regex() or just regular parsing using
SubString()
etc.
Thanks

John-
Feb 4 '08 #4
if as you mentioned in your OP the string is huge (thousands of line) then
regular expression is the way to go
BTW the regex in Arne's post is more accurate

--
Misbah Arefin
"John Rogers" <jo************@aol.comwrote in message
news:uf**************@TK2MSFTNGP02.phx.gbl...
Appreciate the response guys, I didn't try to use regex because its not
that easy to use.

I have been looking at some code like SubString() and stuff like that, it
seems easier
to work with.

Which is faster when parsing strings? Regex() or just regular parsing
using SubString()
etc.
Thanks

John-
Feb 4 '08 #5
Yes it is very fast, I had never used it before but I am super surprised
that it took about
one second to parse a few thousand lines. I just grabbed a Regex() tutorial
from
codeproject, I will read it tomorrow so I can start using this from now on.

Thanks again for your help.

John-

"Misbah Arefin" <Mi**********@discussions.microsoft.comwrote in message
news:72**********************************@microsof t.com...
if as you mentioned in your OP the string is huge (thousands of line) then
regular expression is the way to go
BTW the regex in Arne's post is more accurate

--
Misbah Arefin

Feb 4 '08 #6
Just for completeness; if your data is xml (such as xhtml), another
alternative is an XmlReader; again very quick, but geared towards xml;
if the scanario gets any more complicated, it might be worth
consideration - however, if the regex does what you need, I'd stick
with it! Just be aware that regex can't handle every scenario without
turning into a monster (although the simple case is, er, simple -
html / xml can have some complicated scenarios [just like e-mail]).

Marc
Feb 4 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Gerrit Holl | last post: by
6 posts views Thread by BerkshireGuy | last post: by
3 posts views Thread by aspineux | last post: by
2 posts views Thread by RG | last post: by
6 posts views Thread by gw7rib | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.