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("\nNonCurrently no hex or binary conversion:");
foreach (s; ["0x10", "6b"])
writefln(`isNumeric("%s") = %s`, s, isNumeric(s));
}</lang>
{{out}}
Output:
<pre>isNumeric("12") = true
isNumeric(" 12 ") = true
Line 419:
isNumeric("1.5") = true
 
NoCurrently no hex or binary conversion:
isNumeric("0x10") = false
isNumeric("6b") = false</pre>
</pre>
 
=={{header|Delphi}}==