using IsNumeric Function in c#
-
how to use IsNumeric Function in c# it is working fine in vb.net. i think some namespace should be included. please help me. thanks
Use int.TryParse() method.
string str = "123";
nt num;
if( int.TryParse( str, out num))
{//successfully parsed the string. Now the num variable contains the numeric value if you need it.
//Ok the number is numeric do what ever you want.
}Nirandas, a developer from India. http://www.nirandas.com
-
how to use IsNumeric Function in c# it is working fine in vb.net. i think some namespace should be included. please help me. thanks
I think Regex would be the way to go: return Regex.IsMatch(yourText, "^\d+$"); This would work for simple numbers.
-
You should try to avoid using functions from the VisualBasic namespace.
-
You should try to avoid using functions from the VisualBasic namespace.
-
Le Centriste wrote:
You should try to avoid using functions from the VisualBasic namespace.
So why do you say that? Is that namespace inferior?
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)This package is used to support the VisualBasic runtime.
-
This package is used to support the VisualBasic runtime.
-
Yes I know that, but what is wrong with it? Why should you not use it?
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)Because there are better alternatives in the .NET library. Furthermore, they are legacy. We had a guy here who was using the CInt function to simply convert a string into an integer (he was using VB.NET and was a former VB programmer). His algorithm seemed to be working well but the numbers were not right. I suggested that he uses Int32.Parse instead, just for the heck of it. Coincidentally, Int32.Parse threw an exception instead of converting the number. It turned out the string was not a number, but the scientific representation of a number. CInt was making the best of it by taking the interger part of the number, which was wrong in this case. The reason why Microsoft created VB.NET and added support for the VB runtime is because they wanted to lure VB programmers and make them embrace the .NET platform.
-
Because there are better alternatives in the .NET library. Furthermore, they are legacy. We had a guy here who was using the CInt function to simply convert a string into an integer (he was using VB.NET and was a former VB programmer). His algorithm seemed to be working well but the numbers were not right. I suggested that he uses Int32.Parse instead, just for the heck of it. Coincidentally, Int32.Parse threw an exception instead of converting the number. It turned out the string was not a number, but the scientific representation of a number. CInt was making the best of it by taking the interger part of the number, which was wrong in this case. The reason why Microsoft created VB.NET and added support for the VB runtime is because they wanted to lure VB programmers and make them embrace the .NET platform.
It wouldn't have been CInt since CInt isn't a function - it's a 'macro' built into the VB language. You couldn't use it from C# even if you wanted it. Same goes for CType, CDbl, CStr, DirectCast, etc.
David Anton http://www.tangiblesoftwaresolutions.com C++ to C# Converter C++ to VB Converter C++ to Java Converter VB & C# to Java Converter Java to VB & C# Converter Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: convert VB, C#, or Java to C++/CLI
-
It wouldn't have been CInt since CInt isn't a function - it's a 'macro' built into the VB language. You couldn't use it from C# even if you wanted it. Same goes for CType, CDbl, CStr, DirectCast, etc.
David Anton http://www.tangiblesoftwaresolutions.com C++ to C# Converter C++ to VB Converter C++ to Java Converter VB & C# to Java Converter Java to VB & C# Converter Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: convert VB, C#, or Java to C++/CLI
-
It wouldn't have been CInt since CInt isn't a function - it's a 'macro' built into the VB language. You couldn't use it from C# even if you wanted it. Same goes for CType, CDbl, CStr, DirectCast, etc.
David Anton http://www.tangiblesoftwaresolutions.com C++ to C# Converter C++ to VB Converter C++ to Java Converter VB & C# to Java Converter Java to VB & C# Converter Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: convert VB, C#, or Java to C++/CLI
In fact, I re-read my post and I actually mentioned the guy was using VB.NET.
-
In fact, I re-read my post and I actually mentioned the guy was using VB.NET.
Sorry - I should have read the post more carefully.
David Anton http://www.tangiblesoftwaresolutions.com C++ to C# Converter C++ to VB Converter C++ to Java Converter VB & C# to Java Converter Java to VB & C# Converter Instant C#: VB to C# converter Instant VB: C# to VB converter Instant C++: convert VB, C#, or Java to C++/CLI