469,325 Members | 1,365 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,325 developers. It's quick & easy.

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 1291
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
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.