read Hexadecimal value from string

BCS ao at pathlink.com
Tue Jul 17 14:13:17 PDT 2007


Reply to David,

> Yep, Tango has some very kool functions. But I do want to point out
> that Phobos does have a radix parameter in the toString functions for
> converting a number to a string...sadly not the other way around.
> 

OK, brute force it is ;-b 

|T fromString(T)(char[] str, uint r)
|{
|  T v = T.min;
|  goto start;
|  do
|  {
|    v++;
|  start:
|    if(toString(v,r) == str) return v;
|  }while(v != T.max);
|}

(bonus points if you can find more than three things to object to.)




More information about the Digitalmars-d-learn mailing list