Not sure if it is intended, but the ParseInt function is only valid for positive integers.
This is what I mod'd it to:
public static int ParseInt(string s, int iIndex, int iLen) { int iStop = iIndex + iLen; int iValue = 0;
if(s[iIndex] == '-') iIndex++;
for (int i = iIndex; i < iStop; i++) iValue = (iValue * 10) + (s[i] - 48);
return s[iIndex] == '-' ? iValue * -1 : iValue; }
Sorry, copied wrong code. It should be this:
public static int ParseInt(string s, int iIndex, int iLen) { int iStop = iIndex + iLen; int iValue = 0; int multiplier = 1; if(s[iIndex] == '-') { multiplier = -1; iIndex++; }
return multiplier < 0 ? iValue * multiplier : iValue; }
Log in to post a comment.
Not sure if it is intended, but the ParseInt function is only valid for positive integers.
This is what I mod'd it to:
public static int ParseInt(string s, int iIndex, int iLen)
{
int iStop = iIndex + iLen;
int iValue = 0;
if(s[iIndex] == '-')
iIndex++;
for (int i = iIndex; i < iStop; i++)
iValue = (iValue * 10) + (s[i] - 48);
return s[iIndex] == '-' ? iValue * -1 : iValue;
}
Sorry, copied wrong code. It should be this:
public static int ParseInt(string s, int iIndex, int iLen)
{
int iStop = iIndex + iLen;
int iValue = 0;
int multiplier = 1;
if(s[iIndex] == '-')
{
multiplier = -1;
iIndex++;
}
for (int i = iIndex; i < iStop; i++)
iValue = (iValue * 10) + (s[i] - 48);
return multiplier < 0 ? iValue * multiplier : iValue;
}