diff --git a/ChatTwo/Util/StringUtil.cs b/ChatTwo/Util/StringUtil.cs index 82b4aa5..b92fb62 100755 --- a/ChatTwo/Util/StringUtil.cs +++ b/ChatTwo/Util/StringUtil.cs @@ -4,9 +4,9 @@ namespace ChatTwo.Util; internal static class StringUtil { internal static byte[] ToTerminatedBytes(this string s) { - var unterminated = Encoding.UTF8.GetBytes(s); - var bytes = new byte[unterminated.Length + 1]; - Array.Copy(unterminated, bytes, unterminated.Length); + var utf8 = Encoding.UTF8; + var bytes = new byte[utf8.GetByteCount(s) + 1]; + utf8.GetBytes(s, 0, s.Length, bytes, 0); bytes[^1] = 0; return bytes; }