以字节为单位计算的UTF-8字符串大小? [英] Calc utf-8 string size in bytes?
问题描述
我有一个字符串的 UTF8
。
我需要得到它的大小。 (字节)
I need to get its size. ( bytes)
总是做它 X2
? //我的意思是乘以2 的
有没有.NET功能呢?
is there any .net function for this ?
P.S。
我要问这个问题监守我最新的<一href="http://stackoverflow.com/questions/9760073/memorymappedfile-doesnt-work-with-2-processes/9760573#comment12421178_9760573">question ...我需要(在mempry映射文件)calc下的串偏移(UTF8) - 从另一个进程。的
im asking this question becuase of my latest question ...I need ( in mempry mapped file) to calc the offset of a string ( utf8 ) - from another process..
推荐答案
没有,它并不总是根据实际内容X2为UTF-8和变化。为ASCII字符它是1字节,但也可以写入多个字节为大$ C $的c-点值。你想:
No, it is not always x2 for UTF-8 and changes based on the actual contents. For ASCII characters it is 1 byte, but can go into several bytes for large code-point values. You want:
string s = // your string
int len = Encoding.UTF8.GetByteCount(s);
这篇关于以字节为单位计算的UTF-8字符串大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!