Anonymous user
Determine if a string is numeric: Difference between revisions
Determine if a string is numeric (view source)
Revision as of 17:15, 27 February 2011
, 13 years agoUpdted for D2
(added Fantom example) |
(Updted for D2) |
||
Line 254:
=={{header|D}}==
<lang d>import std.stdio, std.string, std.conv
bool isNumeric(string s) {
try
catch (
return false;
return true;
}
foreach (
writeln(`isNumeric("`, s, `") =
writeln("\nNo hex or binary conversion:");
}</lang>▼
Output:
<pre>isNumeric("12") = true
isNumeric(" 12 ") = true
isNumeric("hello12") = false
isNumeric("-12") = true
isNumeric("02") = true
isNumeric("0-12") = false
isNumeric("+12") = true
isNumeric("1.5") = true
No hex or binary conversion:
isNumeric("0x10") = false
isNumeric("6b") = false</pre>
▲ writefln("isNumeric(", s, ") = ", isNumeric(s));
▲}</lang>
=={{header|E}}==
|