Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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


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


Only letters and numbers:
C#
Regex.IsMatch(input, @"^[a-zA-Z0-9]+$");
 
Share this answer
 
v2
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

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


Hope that helps
-Milind
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900