String to int exception

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 15 06:49:51 PDT 2014


On 07/15/2014 04:56 AM, Alexandre wrote:

 >          retVal = to!int(val);

 > std.conv.ConvException at C:\D\dmd2\src\phobos\std\conv.d(1968): Unexpected
 > '@' when converting from type string to type int

That means to!int failed because 'val' contained a '@' character in it:

import std.conv;

void main()
{
     auto s = "42@";    // <-- What is that?
     auto i = to!int(s);
}

However, there seems to be a bug in to(). It seems to incorrectly go one 
character ahead:

     to!int("mn");

"Unexpected 'n' when converting from type string to type int"

     to!int("m");

"Unexpected end of input when converting from type string to type int"

That is a bug, right?

So, in your case the unexpected '@' character may be after another 
unexpected one:

     to!int(" @");

"Unexpected '@' when converting from type string to type int"

Ali



More information about the Digitalmars-d-learn mailing list