Jump to content

Determine if a string is numeric: Difference between revisions

Updated D entry
(Updated D entry)
Line 391:
<lang d>import std.stdio, std.string, std.conv;
 
bool isNumeric(in string s) /*pure*/ {
try
to!real(s.strip());
Line 402:
foreach (s; ["12", " 12\t", "hello12", "-12", "02",
"0-12", "+12", "1.5"])
writelnwritefln(`isNumeric("`, %s, `") = %s`, s, isNumeric(s));
 
writeln("\nNo hex or binary conversion:");
foreach (s; ["0x10", "6b"])
writelnwritefln(`isNumeric("`, %s, `") = %s`, s, isNumeric(s));
}</lang>
Output:
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.