how to ignore strings starting with numbers

lets say i have a few strings

Welcome
test
123bat
ball456

and I have a foreach looking at all the strings
how can i quickly test if the first char in the string is a number

output should look like

Welcome
test
ball456
no158Asked:
Who is Participating?
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.

DhaestCommented:
string strToTest = "123";
Regex reNum = new Regex(@"^\d+$");
(or regex(@"^\d{5}$");
bool isNumeric = reNum.Match(strToTest).Success

http://www.codeproject.com/KB/cs/csharp-isnumeric.aspx
0
Praveen KumarArchitectCommented:
......

int a;

if(Int32.TryParse(yourstring.SubString(0,1), out a) == true)
    MessageBox.Show("Yes, this is start with number");

....

0
no158Author Commented:
Tried using the regular expression first with this as data

123first test
second123 test
this123third test
123

all of them went through, as if there was no test

Secondly i tried the Int32.TryParse but it seems that my string wont allow substrings


here is what i'm working with


                            foreach (string s in myString)
                            {
                                if (!(startString.Contains(s)))
                                {
                                    Regex reNum = new Regex(@"^\d{5}$");
                                    bool isNumeric = reNum.Match(s).Success;
                                    if (!isNumeric)
                                    {
                                        myString[count] = s;
                                        list = new KeyValueList(myString[count], lineTemp, index);
                                        myList.Add(list);
                                        count++;
                                    }
                                }
                                index++;
                            }

Open in new window

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

DhaestCommented:
Try it with 1 instead of 5
Regex reNum = new Regex(@"^\d{1}$");
0
no158Author Commented:
Didn't work either.

On second thought, it would be better if it would just not accept any string with a digit in it.
If this makes it easier.

So all these would fail the test.

123first
second123
this123third
123
0
ColemssCommented:
internal static bool IsNumeric(string numberString)
{
    foreach (char c in numberString)
   {
        if (!char.IsNumber(c))
             return false;
   }
   return true;
}
0

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
DhaestCommented:
>> On second thought, it would be better if it would just not accept any string with a digit in it.
If this makes it easier.

Does the user needs to input this in a textbox ? Then I would also accept only numeric values, ...
0
no158Author Commented:
internal static bool IsNumeric(string numberString)
{
    foreach (char c in numberString)
   {
        if (!char.IsNumber(c))
             return false;
   }
   return true;
}

worked perfect for what I was doing. Only thing was I used IsDitgit.
0
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
C#

From novice to tech pro — start learning today.