Created
October 6, 2020 03:27
-
-
Save sapphire-al2o3/ba7d6a80836a2e5ee117abb4c3d75132 to your computer and use it in GitHub Desktop.
StringBuilderでintをAppendしたときにToStringされる環境用
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
public static class StringBuilderUtil | |
{ | |
public static void AppendInt(System.Text.StringBuilder sb, int value) | |
{ | |
int n = value; | |
if (n < 0) | |
{ | |
sb.Append('-'); | |
n *= -1; | |
} | |
int k = 1; | |
int m = n; | |
while (m / 10 != 0) | |
{ | |
m /= 10; | |
k *= 10; | |
} | |
while (k != 0) | |
{ | |
int d = n / k; | |
n = n - d * k; | |
k /= 10; | |
char c = (char)('0' + d); | |
sb.Append(c); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment