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

  • Thread starter Thread starter Claire
  • Start date Start date
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)
 
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
 
Back
Top