Re: char* to long

2012-01-25 Thread Mars
Thanks for the replies, everyone.I guess I'll go with the double conversion for now.

char* to long

2012-01-24 Thread Mars
Hello everybody. I have to convert a char* (from a C function) to long. At the moment I'm using long foo = to!long( to!string(bar) ); but this doesn't feel right... with 2 to calls. Is this the way to go? Or is there something better? Mars

Re: char* to long

2012-01-24 Thread Mantis
24.01.2012 22:48, Mars пишет: Hello everybody. I have to convert a char* (from a C function) to long. At the moment I'm using long foo = to!long( to!string(bar) ); but this doesn't feel right... with 2 to calls. Is this the way to go? Or is there something better? Mars This seems to work:

Re: char* to long

2012-01-24 Thread Jonathan M Davis
to go? Or is there something better? Mars This seems to work: char[] c = 123\0.dup; auto l = parse!long(c); writeln( l ); Yeah, but note that that's really equivalent to auto foo = to!long(to!(char[])(bar)); except that you're creating an extra variable and using parse with its

Re: char* to long

2012-01-24 Thread mta`chrono
Why not just go the good old way? you char* should be zero terminated when coming from c. private import core.stdc.stdlib, std.stdio; void main() { const(char)* str = 1234567890.ptr; long lng = atoll(str); writeln(lng); }