Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with Regular Expressions

Status
Not open for further replies.

sm43

Programmer
Dec 1, 2002
155
US
I have this code .

<code>
Regex regDollar= new System.Text.RegularExpressions.Regex(&quot;[0-9]+.[0-9][0-9]&quot;);

inputFile=new StreamReader(path);

buffer=inputFile.ReadLine().TrimStart(null);

Match mObj ;

Total1=decimal.Parse( regDollar.Match(buffer).ToString());

mObj = regDollar.Match(buffer).NextMatch();

Total2=decimal.Parse(mObj.ToString()) ;

mObj = regDollar.Match(buffer).NextMatch() ;

Total3=decimal.Parse(mObj.ToString());

vsSystems.Item(reportSystemID).Materials.Insert(cSINumber,laborTotal+materialTotal+equipmentTotal);

Console.Write(&quot;\nTotal1: + &quot; + Total1 + &quot;\tTotal2 = &quot; + Total2 + &quot;\tTotal3 + &quot; + Total3 + &quot;\n\n\n\n&quot;) ;


The lines that are being retrieved by ReadLine() are like this:

418.25 382.76 12.45



The value retrieved by the third Match (the Total3) is the value retrieved in the second match (Total2). This is always the case for some reason. For instance, in the above example, Total1 would be 418.25, Total2 would be 382.76 and Total3 would also be 382.76 . It should be 12.45 though.

I'm trying to figure out what the problem is but so far I haven't.


Any help in this regard would be appreciated ..


Thanks.


Saad
 
Code:
MatchCollection mObj;
			mObj = regDollar.Matches(buffer,0);
			decimal Total1=decimal.Parse(mObj[0].ToString());
            decimal Total2=decimal.Parse(mObj[1].ToString());
		    decimal Total3=decimal.Parse(mObj[2].ToString());

Try this out, seemed to have worked for me.

Regards,
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top