StringToInt
native int StringToInt(string value);
Convert a string to an integer.
How the function works:
- It skips all the whitespaces at the beginning.
- If the first character is not a digit then it returns 0.
- It returns the number composed of all the consecutives digits and skips what is after
Parameters
- string value
String value. Can be of one of these forms:
- Normal value: "42" -> 42
- Negative values: "-120" -> -120
- Trimming left spaces: " 1" -> 1
- Skip right characters: "30 pounds" -> 30
Examples
- Example #1: Allowed conversion
int i; i = StringToInt("-10"); // i = -10; i = StringToInt("30 pounds"); // i = 30 i = StringToInt(" 1 "); // i = 1
- Example #2: Disallowed conversion
i = StringToInt("-"); // i = 0 i = StringToInt("sc2mapster"); // i = 0