An unexpected string to int exception.

Taylor Hillegeist via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 17 08:38:34 PST 2016


On Wednesday, 17 February 2016 at 16:13:47 UTC, Taylor Hillegeist 
wrote:
> On Wednesday, 17 February 2016 at 16:11:44 UTC, Taylor 
> Hillegeist wrote:
>> I think the following error message says it all.
>>
>> std.conv.ConvException at C:\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(2002): Unexpected '1' when converting from type string to type int
>>
>> I would expect that 1 would be among the group of expected 
>> items.
>
> Also how rude of me:
>
> DMD32 D Compiler v2.070.0
>
> code segment in question
> +++++
> 		if(l.style.canFind("Heading")){
> 			string tmp = l.style[6..$];
> 			ON.incrementNum( to!int(tmp));
> +++++

So my error here was i was slicing too early.
string tmp = l.style[6..$];
should have been:
string tmp = l.style[7..$];

apparently std.conv parse() will say the unexpected input is not 
the one that caused the error but the character after. in this 
case
"g1" only the 1 was reported.


More information about the Digitalmars-d-learn mailing list