Link to home
Start Free TrialLog in
Avatar of NewMom2Brandon
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.
ASKER CERTIFIED SOLUTION
Avatar of GENTP
GENTP

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NewMom2Brandon
NewMom2Brandon

ASKER

Thank you!!
Avatar of Fernando Soto
Hi NewMom2Brandon;

This solution uses Regular Expressions. The variable will have the results, the first digits in the string.

using System.Text.RegularExpressions;

      string input = "1 black cat jumped false true 1";
      Match m = Regex.Match(input, @"\s*?(\d+)");
      string results = m.Groups[1].Value;


Fernando