List Info

Thread: determining substring length




determining substring length
user name
2006-01-25 19:23:47
This is probably something really simple, but I haven't
found an answer
just by browsing so I figured I'd just ask....

First the code:

                string s = Regex.Match(val,
"[0-9].[0-9]+" x
[0-9]").Value;
                string num1 = s.Substring(0, ???);
                string num2 = s.Substring(s.IndexOf('x') +
2, 1);
                double num01 = Double.Parse(num1);
                double num02 = Double.Parse(num2);
                double dec = (num01 * num02) / 70;
                return dec;

What i'm  trying to do is tell num1 that its length is the
distance
between the start of the match, and the first " .

determining substring length
user name
2006-01-27 20:24:23
Well, I came up with a fix of sorts... I'll post it incase
anyone else
is wondering the same thing....

string s = Regex.Match(val, "[0-9].[0-9]+(") x
[0-9]").Value;
string lengthto = s.Substring(0,s.IndexOf('"'));
string num1 = s.Substring(0, lengthto.Length - 1);
string num2 = s.Substring(s.IndexOf('x') + 2, 1);
double num01 = Double.Parse(num1);
double num02 = Double.Parse(num2);
double dec = (num01 * num02) / 70;
return dec;

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )