NewMom2Brandon
asked on
trim a string
I need to trim a string. What I need to trim off is anything following the first number(s)
for example
1 black cat jumped false true 1
12 red cat sat true false 2
123 Yellow dog sat true false 2
So all I want is the 1, 12 or 123.
How do I go about doing this. So basically anything following the first number. I can't set a length for the number becasue it is incremented based on the number of entries the user adds on another form.
for example
1 black cat jumped false true 1
12 red cat sat true false 2
123 Yellow dog sat true false 2
So all I want is the 1, 12 or 123.
How do I go about doing this. So basically anything following the first number. I can't set a length for the number becasue it is incremented based on the number of entries the user adds on another form.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi NewMom2Brandon;
This solution uses Regular Expressions. The variable will have the results, the first digits in the string.
using System.Text.RegularExpress ions;
string input = "1 black cat jumped false true 1";
Match m = Regex.Match(input, @"\s*?(\d+)");
string results = m.Groups[1].Value;
Fernando
This solution uses Regular Expressions. The variable will have the results, the first digits in the string.
using System.Text.RegularExpress
string input = "1 black cat jumped false true 1";
Match m = Regex.Match(input, @"\s*?(\d+)");
string results = m.Groups[1].Value;
Fernando
ASKER