Bug 6255 – Add support for different base conversions in std.conv
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-07-05T14:58:00Z
Last change time
2012-01-26T00:04:21Z
Keywords
patch
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2011-07-05T14:58:40Z
This doesn't work currently:
to!int("0xFF");
Python's int() function solves this by taking an optional base argument:
http://docs.python.org/library/functions.html#int
So it can be called like:
clr = int("0000FF", 16)
I've seen this used in some functions which convert web colors to an integer.
So std.conv could take an optional base argument or maybe try to parse the string and figure out if it's hexadecimal (since this is probably the most commonly used base after base-10).
Comment #1 by andrej.mitrovich — 2011-07-05T14:59:31Z
I should have mentioned in the title that I'm looking for *string* to int conversions.
Comment #2 by yebblies — 2011-07-05T19:01:42Z
Looking at the docs, it seems there's parse!int(string, radix) and to!string(int, radix). It's probably worth adding to!int(string, radix) as well (unless it's already there and not showing up in the docs)
Comment #3 by yebblies — 2011-12-13T18:25:18Z
*** Issue 6992 has been marked as a duplicate of this issue. ***