- Home /
Question by
drudiverse · Aug 25, 2014 at 10:09 PM ·
int.netchar
Converting fastParseInt to JS from C
I have found a cool script to convert int string to an integer, it is 10 times faster than int.Parse because it doesnt have to search for - and spaces and returns in the string.
I started to convert it to JS, except that JS doesnt add a char to an int (can't add result and letter at the end), so is there a .net method for it? Thankyou
function IntParseFast( value : String) : int
{
var result : int = 0;
for (var i = 0; i < value.Length; i++)
{
var letter : char = value[i];
result = 10 * result + (letter);
}
return result;
}
Comment
Best Answer
Answer by robertbu · Aug 26, 2014 at 02:02 AM
Try char.GetNumericValue():
result = 10 * result + char.GetNumericValue(letter);
Awesome thanks! here is the result:
int.Parse("400") 123.07 ns IntParseFast("400") 2.87 ns
Your answer
Follow this Question
Related Questions
Error CS0029 fix 1 Answer
Convert a char to int / float 2 Answers
using char to extract integer numbers from a list - [UnityScript] 1 Answer
int to char conversion in JS ? 2 Answers
Float to Int 4 Answers