Converting string to ascii value

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Mar 7 14:33:24 PST 2014


On Fri, Mar 07, 2014 at 10:21:57PM +0000, Setra wrote:
> On Friday, 7 March 2014 at 22:21:06 UTC, Setra wrote:
> >Hello all! I am having trouble converting a letter in a array of
> >string to the ascii value. For example:
> >
> >string[] stringarray[3];
> >stringarray[0] = "blahblahblah";
> >stringarray[1] = "a";
> >stringarray[2] = "5";
> >
> >long y = to!long(stringarray[2]); // makes y the value 5
> >long x = to!long(stringarray[1]); // errors
> >
> >
> >This is not working properly. I want to get the ascii value of the
> >characters.
> >In this case y should equal 97, b should equal 53. How do I do
> >this properly?
[...]

long x = cast(ubyte) stringarray[0];

Using to!long is for when you're trying to parse a number represented in
string format.


T

-- 
Famous last words: I *think* this will work...


More information about the Digitalmars-d-learn mailing list