472,133 Members | 1,090 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

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

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)
Nov 16 '05 #1
2 1354
Claire <bl****@blahhhhh.com> wrote:
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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Thanks Jon
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Richard Lewis | last post: by
1 post views Thread by Wes Groleau | last post: by
7 posts views Thread by EmeraldShield | last post: by
4 posts views Thread by EmeraldShield | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.