Given an array of string
, I want to find the first one that can be successfully converted to a real
without using exceptions.
The only relevant functions I can see in Phobos are std.conv.to
and std.conv.parse
, but both of these will throw an exception if they cannot convert the string. I'd like to avoid exceptions because this is not going to be an exceptional circumstance for my use case.
C# provides TryParse
for exactly this. Is there anything similar in D?
(of course, I could parse the string myself to determine if it is convertible to real
, but it's non-trivial so I'd like to avoid that if possible).
Phobos doesn’t appear to have a way to do this without exceptions, besides
std.stream
. The problem is thatstd.stream
seems to be deprecated. Here is an example usingsscanf
withdouble
, though I don’t know how to do it withreal
: