public static BigInteger Parse(string number) {
if (number == null)
throw new ArgumentNullException(number);
int i = 0, len = number.Length;
char c;
bool digits_seen = false;
BigInteger val = new BigInteger(0);
if (number[i] == '+') {
i++;
} else if(number[i] == '-') {
throw new FormatException("Only positive integers are allowed.");
}
for(; i < len; i++) {
c = number[i];
if (c == '\0') {
i = len;
continue;
}
if (c >= '0' && c <= '9'){
val = val * 10 + (c - '0');
digits_seen = true;
} else {
if (Char.IsWhiteSpace(c)){
for (i++; i < len; i++){
if (!Char.IsWhiteSpace (number[i]))
throw new FormatException();
}
break;
} else
throw new FormatException();
}
}
if (!digits_seen)
throw new FormatException();
return val;
}