Numeric access to char[]

Unknown W. Brackets unknown at simplemachines.org
Tue Aug 22 07:11:48 PDT 2006


Do you want the numeric (integer/float) value of the string in a char[]?

For example, "1.0" => 1.0, and similar?

In other words, something similar to:

$x = (int) '324';
$y = intval('562');
$z = '324' + '9';

In PHP?  If so, you want std.conv.  The D code might look like this:

x = toInt(324);
y = toInt(562);
z = toInt(324) + toInt(9);

There's also toFloat, toDouble, toUint, etc.  See:

http://digitalmars.com/d/phobos/std_conv.html

Please note that an Exception is thrown if it cannot be converted, it 
won't just be made 0.  So, for example:

try
	x = toInt(user_value);
catch (ConvError)
	x = 0;
catch (ConvOverflowError)
	x = int.max;

Or something like that.

If that's not what you want, a char[] is actually two numeric values - 
much like in PHP.  It is a length value, and a pointer.  Bit shifting 
these probably won't give you anything interesting.

-[Unknown]


> Hi,
> 
> how is it possible to work on the numeric value of a char[]? I'm interested
> in bit shifting and arithmetic operations on the numeric value.
> 
> Thanks!
> Peter



More information about the Digitalmars-d-learn mailing list