Skip to content

Instantly share code, notes, and snippets.

@sapphire-al2o3
Created October 6, 2020 03:27
Show Gist options
  • Save sapphire-al2o3/ba7d6a80836a2e5ee117abb4c3d75132 to your computer and use it in GitHub Desktop.
Save sapphire-al2o3/ba7d6a80836a2e5ee117abb4c3d75132 to your computer and use it in GitHub Desktop.
StringBuilderでintをAppendしたときにToStringされる環境用
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