I would like to get the number of bytes in a string using UTF-8 encoding without explicitly creating an array of bytes (because I do not need to use the array, just the number of bytes). Is this possible? My question is almost exactly this one but with C# instead of Java.
Thanks!
You can use the method GetByteCount to get the number of bytes that the string would produce with a given encoding.
var byteCount = System.Text.Encoding.UTF8.GetByteCount("myString");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With