I know a few ways how to check this.
regex,int.parse
,tryparse
,looping.
can anyone tell me what is the fastest way to check?
the nee
You can try using Regular Expressions by testing the input string to have only digits (0-9) by using the .IsMatch(string input, string pattern)
method in C#.
using System;
using System.Text.RegularExpression;
public namespace MyNS
{
public class MyClass
{
public void static Main(string[] args)
{
string input = Console.ReadLine();
bool containsNumber = ContainsOnlyDigits(input);
}
private bool ContainOnlyDigits (string input)
{
bool containsNumbers = true;
if (!Regex.IsMatch(input, @"/d"))
{
containsNumbers = false;
}
return containsNumbers;
}
}
}
Regards