Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I check if a string is a positive integer?

Tags:

c#

int

parsing

I mean :

1231 YES
121.1241 NO
121,1241 NO
-121 NO
124a NO

how can i do it faster in C#?

like image 319
markzzz Avatar asked Apr 15 '12 13:04

markzzz


People also ask

How do you check if a string is a positive integer in Python?

Python's isnumeric() function can be used to test whether a string is an integer or not. The isnumeric() is a builtin function. It returns True if all the characters are numeric, otherwise False.

How do you validate a positive number in JavaScript?

function isInteger(num) { return (num ^ 0) === num; } console. log(isInteger(1));

How do you check if a string is integer in JS?

isInteger() method returns true if a value is an integer of the datatype Number. Otherwise it returns false .


1 Answers

int x;
if (int.TryParse(str, out x) && x > 0)
like image 75
SLaks Avatar answered Nov 15 '22 16:11

SLaks