473,385 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1588
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
6
by: BerkshireGuy | last post by:
Does anyone know of a good function that will parse out parts of an SQL statement that is passed to it in seperate variables? It should be able to parse statements that contain ORDERBY, WHERE,...
9
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an...
3
by: Anup Daware | last post by:
Hi Group, I am facing a strange problem here: I am trying to read xml response from a servlet using XmlTextWriter. I am able to read the read half of the xml and suddenly an exception:...
3
by: aspineux | last post by:
My goal is to write a parser for these imaginary string from the SMTP protocol, regarding RFC 821 and 1869. I'm a little flexible with the BNF from these RFC :-) Any comment ? tests= def...
2
by: RG | last post by:
I am having trouble parsing the data I need from a Serial Port Buffer. I am sending info to a microcontroller that is being echoed back that I need to remove before I start the actual important...
6
by: gw7rib | last post by:
I have a program that needs to do a small amount of relatively simple parsing. The routines I've written work fine, but the code using them is a bit long-winded. I therefore had the idea of...
1
by: hd95 | last post by:
In a perfect world my xml feed source would produce perfect xml ..that is not the case I am parsing an XML feed that sometimes has ampersands and dashes in the content that messes up my parsing. ...
1
by: eyeore | last post by:
Hello everyone my String reverse code works but my professor wants me to use pop top push or Stack code and parsing code could you please teach me how to make this code work with pop top push or...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.