"James Hahn" <jh***@yahoo.comwrote in message
news:uo**************@TK2MSFTNGP06.phx.gbl...
Take a look at the MatchCollection class. This will return the matches
from the regular expression as a collection, each element of which has a
value (or ToString), length and index, whch is the position in the source
where the matched substring occured. If you construct your regular
expression properly then item 0 (which might be null) is the portion you
are after.
That was exactly what I did.
But then I ran into another problem.
I am moving this into an SqlParameter, but I can't seem move it directly
into the parameter.Value.
SqlParameter parameter = new SqlParameter("@" +
"PCVOrderID", SqlDbType.Int);
System.Text.RegularExpressions.Match oMatch =
System.Text.RegularExpressions.Regex.Match(Path.Ge tFileName(AppSettings.PCVFileName),
"(\\d*)");
Int32.TryParse(oMatch.Groups[1].Value, out
(int)(parameter.Value));
The error I get is:
a ref or out arguement must be an assignable value.
This is.
I tried using
parameter.Value
(int)parameter.Value
And got the same error.
I can do:
parameter.Value = Convert.ToInt32(tf.SectionNumber);
So it is obviously assignable.
And I can do:
parameter = new SqlParameter("@" + "PCVOrderID",
SqlDbType.Int);
System.Text.RegularExpressions.Match oMatch =
System.Text.RegularExpressions.Regex.Match(Path.Ge tFileName(AppSettings.PCVFileName),
"(\\d*)");
Int32.TryParse(oMatch.Groups[1].Value, out iTemp);
parameter.Value = iTemp;
cmd.Parameters.Add(parameter);
Why can't I put parameter.Value there?
Thanks,
Tom
"tshad" <tf*@dslextreme.comwrote in message
news:Og*************@TK2MSFTNGP06.phx.gbl...
>Maybe a substring with a regular expression? I know how to strip
non-numerics using a regular expression but how do I grab the numbers
until I get a non-numeric then stop. I can also do this in a for-loop
but I was looking to see if there was a different way.
I don't have to do this, but was curious if there was a way.
Thanks,
Tom
"tshad" <tf*@dslextreme.comwrote in message
news:Ok**************@TK2MSFTNGP02.phx.gbl...
>>>I have a filename that I want to extract the 1st set of numbers up to
either a ".", "-", "_" or "~" and make that an int.
Or I guess easier just take all the values that are 0-9 up to the 1st
non number value.
So that if I have a value 449231.xml or 449231~1.xml or 449231-1a.xml, I
want to get the 449231 only and make that an integer.
Can that be done in one statement?
Thanks,
Tom