G Guest Aug 19, 2005 #2 Hi ad, What exactly did you mean by "composite of number"? Could you please describe in more detail what you are trying to accomplish?
Hi ad, What exactly did you mean by "composite of number"? Could you please describe in more detail what you are trying to accomplish?
A ad Aug 19, 2005 #3 It must be composite of char 0..9 Thank Rakesh Rajan said: Hi ad, What exactly did you mean by "composite of number"? Could you please describe in more detail what you are trying to accomplish? -- HTH, Rakesh Rajan MVP, MCSD http://www.msmvps.com/rakeshrajan/ Click to expand...
It must be composite of char 0..9 Thank Rakesh Rajan said: Hi ad, What exactly did you mean by "composite of number"? Could you please describe in more detail what you are trying to accomplish? -- HTH, Rakesh Rajan MVP, MCSD http://www.msmvps.com/rakeshrajan/ Click to expand...
O Octavio Hernandez Aug 19, 2005 #4 Hi, You can use: bool IsInteger(string s) { try { int n = int.Parse(s); return true; } catch { return false; } This will accept a '+' or '-' sign in front of a number. If you don't want that, you could write your own function: bool IsInteger(string s) { for (int i = 0; i < s.Length; i++) if (s < '0' || s > '9') return false; return true; } Check against a regular expression could be another solution. Regards - Octavio
Hi, You can use: bool IsInteger(string s) { try { int n = int.Parse(s); return true; } catch { return false; } This will accept a '+' or '-' sign in front of a number. If you don't want that, you could write your own function: bool IsInteger(string s) { for (int i = 0; i < s.Length; i++) if (s < '0' || s > '9') return false; return true; } Check against a regular expression could be another solution. Regards - Octavio
O Oliver Sturm Aug 19, 2005 #5 Octavio said: Check against a regular expression could be another solution. Click to expand... Yep, and much easier: if (Regex.IsMatch(myString, "\d+")) // myString contains at least one character 0-9 Oliver Sturm
Octavio said: Check against a regular expression could be another solution. Click to expand... Yep, and much easier: if (Regex.IsMatch(myString, "\d+")) // myString contains at least one character 0-9 Oliver Sturm
G Guest Aug 28, 2005 #7 That was real clever Oliver BTW, I think the regex should be "^\d+$" -- HTH, Rakesh Rajan MVP, MCSD http://www.msmvps.com/rakeshrajan/
That was real clever Oliver BTW, I think the regex should be "^\d+$" -- HTH, Rakesh Rajan MVP, MCSD http://www.msmvps.com/rakeshrajan/