Anonymous user
Determine if a string is numeric: Difference between revisions
Updated D entry
(Updated D entry) |
|||
Line 392:
<lang d>import std.stdio, std.string, std.conv;
bool isNumeric(in string s) /*pure nothrow*/ {
try
to!real(s.strip());
Line 405:
writefln(`isNumeric("%s") = %s`, s, isNumeric(s));
writeln("\
foreach (s; ["0x10", "6b"])
writefln(`isNumeric("%s") = %s`, s, isNumeric(s));
}</lang>
{{out}}
<pre>isNumeric("12") = true
isNumeric(" 12 ") = true
Line 419:
isNumeric("1.5") = true
isNumeric("0x10") = false
isNumeric("6b") = false
</pre>
=={{header|Delphi}}==
|