如何获得字符串中的字节数 [英] How do you get the number of bytes in a string
本文介绍了如何获得字符串中的字节数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问候,
什么是返回字符串中字节数的C#代码,如
32313131353131333432317E547E3132357E5553447E467E35 36363031303030343835323632 >
7E307E56
我认为应该是80.
谢谢
grs
Greetings,
What is the C# code that returns the number of bytes in a string such as
32313131353131333432317E547E3132357E5553447E467E35 36363031303030343835323632
7E307E56
It should be 80 I think.
thanks
grs
推荐答案
好吧,没有什么可以返回字节数,但是
String.Length会返回字符数。
char是unicode,这是16位,所以字符串至少是
160字节(实际上我算了83个字符,所以166+字节)
-
hotmail帐户很可能不会被阅读,所以请只回复
给新闻组。
Well, there is nothing that would return the number of bytes, but
String.Length would return the number of characters.
A char would be unicode, which is 16 bits, so the string would be at least
160 bytes (actually I counted 83 characters, so 166+ bytes)
--
The hotmail account will most likely not be read, so please respond only
to the news group.
Morten,
谢谢
我害怕我想要一个sizeof。
packet.length返回162,所以我猜我们为''x0减去2 '结束
字符串给160和160/2给我们80字节,这是规格说的
字节数是。
这看起来是否正确。
grs
" Morten Wennevik" <莫************ @ hotmail.com>在消息中写道
news:op ************** @ msnews.microsoft.com ...
Morten,
thanks
I was afraid of that I would like a "sizeof".
The packet.length return 162, so I guess we subtract 2 for the ''x0'' end of
string giving 160 and 160 / 2 gives us 80 bytes which is what the specs say
the number of bytes is.
Does this seem correct.
grs
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:op**************@msnews.microsoft.com...
好没有什么可以返回字节数,但是
String.Length会返回字符数。
一个char是unicode,它是16位,所以字符串至少是
160个字节(实际上我算了83个字符,所以166个字节以上)
-
hotmail帐户很可能无法读取,所以请只回复
新闻组。
Well, there is nothing that would return the number of bytes, but
String.Length would return the number of characters.
A char would be unicode, which is 16 bits, so the string would be at least
160 bytes (actually I counted 83 characters, so 166+ bytes)
--
The hotmail account will most likely not be read, so please respond only
to the news group.
有一个sizeof运算符,但我认为这只会显示
类/结构大小。
sizeof(String);
此外,sizeof仅适用于''不安全''代码块。
-
Hotmail帐户很可能无法阅读,因此请仅回复
给新闻组。
There is a sizeof operator but I think that would only show you the
class/structure size.
sizeof(String);
Also, sizeof only works with the ''unsafe'' code blocks.
--
The hotmail account will most likely not be read, so please respond only
to the news group.
这篇关于如何获得字符串中的字节数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文