UTF8 encoding, calculating space that string will take up in a file

C

Claire

Is there an easy way to calculate the number of bytes that a UTF8 encoded
string will occupy within a file in advance of writing?
I am writing records to a complex file. These records contain variable
length strings and I need to be able to work out in advance whether to
overwrite the old record (if the string occupies the same or less bytes) or
append a new one (if the string occupies more)
 
J

Jon Skeet [C# MVP]

Claire said:
Is there an easy way to calculate the number of bytes that a UTF8 encoded
string will occupy within a file in advance of writing?

You can use Encoding.UTF8.GetByteCount
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top