Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Parsing Strings w/ No RegEx Experience


Message #1 by "Phil McAllister" <PhilMc@8...> on Fri, 7 Jun 2002 12:14:57 -0700
Hello,

Another solution (if the variable is not the only one in the string) :-
(Sorry this is in C#, I have not looked at VB)

			// this will find the index of the string that you are looking for
			string sSearch = "All Important";
			int index = strElusive.IndexOf(sSearch);
			index = index + sSearch.Length;

			// remove everything before the variable
			string tempResult = strElusive.Substring(indedx);
			// remove everything after the first " " (assuming that you are getting the first word as the variable)
			tempResult = tempResult.Substring(0,tempResult.IndexOf(" "));

Now you (should) have the correct string.

Another way would be to use the Split function, if you had a deliminator between the variable, as you would when parsing a url.
			string urlString = "?pageid=2&section=3&line=234";
			string sSearch = "All Important";
			//make the array
			string[] Results = urlString.Split(new char[1]{'&'});
			// Results is now an array which holds the key=value pairs
			for (int index = 0;index < Results.Count;index++)
			{
				if(Results[index].IndexOf(sSearch) > 0)
				{
					sValue = Results[index].Substring(sSearch.Length);
				}
			}
			// at this ponit sValue should contain the =value string

Probably very buggy and the long way round, but at least you don't have to worry about RegExp.
Saying that though the RegExp namespace in .NET is reasonably simple to use.

HTH,

Aiden

-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: 10 June 2002 13:18
To: ASPX_Professional
Subject: [aspx_professional] RE: Parsing Strings w/ No RegEx Experience


Phil,

> What if I had no experience in (nor time to learn) Regular Expressions,
and
> wanted to parse a string in ASP.NET (VB) . . . is it possible?

	NO!  You must learn everything there is to know about regular
expressions, starting with RFC 718 and continuing with RFC 721, 738, 740,
741, etc etc.

	Does the line always begin with "ALL IMPORTANT" and you only want to
capture text until the end of the line?  If so, a pattern that looks
something like the following might work:

"^ALL IMPORTANT.$"

and to make things even easier, just Substring(14) the returned string to
knock off the "ALL IMPORTANT".  However, if this doesn't solve the problem,
then please describe what you're trying to do in furthur detail.

- Chuck

Yes, I made those RFC numbers up, they probably aren't the correct numbers
for the RegExp RFCs.

-----Original Message-----
From: Phil McAllister [mailto:PhilMc@8...]
Sent: Friday, June 07, 2002 3:15 PM
To: ASPX_Professional
Subject: [aspx_professional] Parsing Strings w/ No RegEx Experience


Hello All,

What if I had no experience in (nor time to learn) Regular Expressions, and
wanted to parse a string in ASP.NET (VB) . . . is it possible?  Here is what
I want to do.  I want to receive a string variable (let's say "strElusive")
that contains, say, "A bunch of words, but all I want to capture is ALL
IMPORTANT [EverChangingAnyValue].".  Please note that I will not ever know
what the value of "[EverChangingAnyValue]" is from one situation to the
next.  Also, please note that my  [EverChangingAnyValue] always follows the
words: "ALL IMPORTANT".  What I want to do is capture just the value of
[EverChangingAnyValue] . . . if anyone can help me please let me know.
Thanks.

Phil




  Return to Index