Click here to Skip to main content
14,661,076 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am reading a file line by line and want to check if the line contains numbers.
for example:if line is startDrag(0,0,500,660) or startDrag(false,0,0,500,660) it should return true else it should return false.
The numbers can be vary.

How to check for such string?
Posted

Rate this:
Please Sign up or sign in to vote.

Solution 1

Only numbers:
Regex.IsMatch("Your string", @"^[0-9]+$");


Only letters:
Regex.IsMatch(input, @"^[a-zA-Z]+$");


Only letters and numbers:
Regex.IsMatch(input, @"^[a-zA-Z0-9]+$");
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

let me re-phrase what I understood: If the line you read contains any integer (0 through 9), consider True.

Probably you can use regex as below

public bool checkContainsIntegar(string myString)
{
  Regex myCheck = new Regex("^[0-9]*$");
  if (myCheck.IsMatch(myString))
    return true;
  else 
    return false;
}


Hope that helps
-Milind
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100