Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check if my string contain text?

Tags:

c#

winforms

if i have this string:

12345 = true

123a45 = false

abcde = false

how to do it in C#?

like image 921
Gali Avatar asked Jan 20 '23 09:01

Gali


2 Answers

Regex.IsMatch(sinput,@"\d+"); 

to match a string containing just digits. If you forgot an optional digit in the question, use this:

Regex.IsMatch("+12345", @"[+-]?\d+");
like image 129
Felice Pollano Avatar answered Jan 28 '23 15:01

Felice Pollano


If you want to avoid RegEx, then you can use the built-in char methods:

bool allDigits = s.All(c => char.IsDigit(c));
like image 33
Joe Enos Avatar answered Jan 28 '23 13:01

Joe Enos