Last active
January 8, 2019 14:10
-
-
Save shaunsales/89531edbf5540fb53ba2c36d153fcfb0 to your computer and use it in GitHub Desktop.
Fast String to Int Converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Our example symbol | |
var symbol = "ABC-1234"; | |
// Get the last 4 digits of our symbol | |
var str = symbol.AsSpan(4, 4); | |
var base10 = 0; | |
for (i = 0; i < 4; i++) | |
{ | |
// Iterate through each digit, multiply the result by 10 for | |
// each digit we add based on its ASCII value | |
base10 = base10 * 10 + (str[i] - 48); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment