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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If then is a space always after the number then use the substring method

string myString = "1 black cat jumped false true 1";

int myNumber = Convert.ToInt32(myString.Substring(0,myString.IndexOf(" ")));

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NewMom2BrandonAuthor Commented:
Thank you!!
Fernando SotoRetiredCommented:
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;

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.