Skip to content

Instantly share code, notes, and snippets.

@shaunsales
Last active January 8, 2019 14:10
Show Gist options
  • Save shaunsales/89531edbf5540fb53ba2c36d153fcfb0 to your computer and use it in GitHub Desktop.
Save shaunsales/89531edbf5540fb53ba2c36d153fcfb0 to your computer and use it in GitHub Desktop.
Fast String to Int Converter
// 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