EvilZone

Programming and Scripting => .NET Framework => : bubzuru August 03, 2012, 01:48:11 AM

: (C#) IsNumeric
: bubzuru August 03, 2012, 01:48:11 AM
do i realy need to explain ?
: (c#)
        public bool IsNumeric(string str)
        {
            foreach (Char c in str)
            {
                if (!Char.IsNumber(c))
                {
                    return false;
                }
            }
            return true;
        }
: Re: (C#) IsNumeric
: techb August 03, 2012, 04:15:08 AM
I don't want to sound rude or anything, but why? A quick Google search would yeild the same thing,  or a we quick glance of the doc's.

Either way, I've noticed a lot more activity from you. Nice.
: Re: (C#) IsNumeric
: bubzuru August 03, 2012, 06:52:35 AM
I don't want to sound rude or anything, but why? A quick Google search would yeild the same thing,  or a we quick glance of the doc's.

Either way, I've noticed a lot more activity from you. Nice.

you would think so , but thats the thing there is no inbuilt IsNumeric function in C#
that surprised me to, thats why i posted the function
: Re: (C#) IsNumeric
: Kulverstukas August 03, 2012, 10:19:29 AM
seriously? no built-in function like that? :D lol, Microsoft...
: Re: (C#) IsNumeric
: Satan911 August 03, 2012, 04:57:33 PM
There's no isNumeric function in Java either for the String class. You can use Integer.parseInt which will throw an exception if the string is not a number but that's a really bad use of exceptions. Added a function just like the on Bubzuru posted in my utility class last week.

P.s. There is a isNumeric() function the Apache StringUtils library.
: Re: (C#) IsNumeric
: Deque August 04, 2012, 09:39:10 AM
Your method only works for integers. You should call it isInteger() instead of isNumeric(), otherwise a String like "1.3" will be considered as non-numeric.
: Re: (C#) IsNumeric
: bubzuru August 04, 2012, 11:15:21 PM
Your method only works for integers. You should call it isInteger() instead of isNumeric(), otherwise a String like "1.3" will be considered as non-numeric.

^^ that is true , this function does not work for floating point numbers.
if anybody needs a workaround please post here 
: Re: (C#) IsNumeric
: fruitcake2212 August 08, 2012, 11:07:26 AM
There's no isNumeric function in Java either for the String class. You can use Integer.parseInt which will throw an exception if the string is not a number but that's a really bad use of exceptions.

You can use the TryParse method instead, it will not throw exception.

Also, you could use the IsNumeric function of VisualBasic in your C# application. You would need to reference the visualbasic dll in your project
: Re: (C#) IsNumeric
: Deque August 08, 2012, 12:41:24 PM
TryParse is a C# method, not Java.
: Re: (C#) IsNumeric
: fruitcake2212 August 08, 2012, 12:59:55 PM
TryParse is a C# method, not Java.

Yes sorry I've read Satan911's answer too fast. My answer are possibilities for C#