Created
January 29, 2021 01:45
-
-
Save sapphire-al2o3/f793f4b6e879b89e6ef7a08c45fd4e86 to your computer and use it in GitHub Desktop.
部分文字列から数値をパースする
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
static int ParseInt(string t, int s, int l) | |
{ | |
if (string.IsNullOrEmpty(t)) | |
{ | |
return 0; | |
} | |
if (s + l > t.Length) | |
{ | |
l = t.Length - s; | |
} | |
int n = 0; | |
for (int i = s; i < s + l; i++) | |
{ | |
n = n * 10 + t[i] - '0'; | |
} | |
return n; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment