Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function int StrToInt(str s)
- {
- int integer = 0;
- bool negative = GetChar(s, 0)=='-';
- int j;
- int i = 0;
- if (GetChar(s, 0) == '-' || GetChar(s, 0) == '+')
- i++;
- for(; i < StrLen(s); i++)
- {
- int c = GetChar(s, i);
- if (c < '0' || c > '9') return 0; // invalid int
- c -= '0';
- int multiplier = StrLen(s)-i;
- for (j = 1; j < multiplier; j++)
- c *= 10;
- integer += c;
- }
- if (negative) integer = -integer;
- return integer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement