在.net中怎么得到 "abc李123" 的字节数 即:长度为 8
用什么函数或用什么方法?
6 个解决方案
#1
length
or:
if it is a moneystream
stream.Length
or:
if it is a moneystream
stream.Length
#2
Dim a As String="你好!"
Dim b As Byte
Dim ofs As Integer
Dim p As IntPtr = System.Runtime.InteropServices.Marshal.StringToCoTaskMemAnsi(a)
Do
b = System.Runtime.InteropServices.Marshal.ReadByte(p, ofs)
ofs += 1
Loop Until b = 0
MsgBox(ofs - 1)
ofs-1 就是长度
Dim b As Byte
Dim ofs As Integer
Dim p As IntPtr = System.Runtime.InteropServices.Marshal.StringToCoTaskMemAnsi(a)
Do
b = System.Runtime.InteropServices.Marshal.ReadByte(p, ofs)
ofs += 1
Loop Until b = 0
MsgBox(ofs - 1)
ofs-1 就是长度
#3
dim str as string="abc李123"
dim strLenth as Integer=System.Text.UnicodeEncoding.Default.GetByteCount(str)
msgbox(strLenth)
dim strLenth as Integer=System.Text.UnicodeEncoding.Default.GetByteCount(str)
msgbox(strLenth)
#4
string str="abc李123";
int strlength = str.length;
MessageBox.Show(strlength.ToString());
#5
解决办法如下,str为要检测的字符串:
ASCIIEncoding n = new ASCIIEncoding();
byte[] b = n.GetBytes(str);
int l = 0; // l 为字符串之实际长度
for (int i=0;i <= b.Length-1;i++)
{
if (b[i] ==63) //判断是否为汉字或全脚符号
{
l++;
}
l++;
}
------------------------------------------------------------------------
马上要升星星了,请都给分 ,争取不穿裤衩过年 :^_^
ASCIIEncoding n = new ASCIIEncoding();
byte[] b = n.GetBytes(str);
int l = 0; // l 为字符串之实际长度
for (int i=0;i <= b.Length-1;i++)
{
if (b[i] ==63) //判断是否为汉字或全脚符号
{
l++;
}
l++;
}
------------------------------------------------------------------------
马上要升星星了,请都给分 ,争取不穿裤衩过年 :^_^
#6
System.Text.Encoding.GetEncoding("GB2312").GetByteCount("abc李123")
#1
length
or:
if it is a moneystream
stream.Length
or:
if it is a moneystream
stream.Length
#2
Dim a As String="你好!"
Dim b As Byte
Dim ofs As Integer
Dim p As IntPtr = System.Runtime.InteropServices.Marshal.StringToCoTaskMemAnsi(a)
Do
b = System.Runtime.InteropServices.Marshal.ReadByte(p, ofs)
ofs += 1
Loop Until b = 0
MsgBox(ofs - 1)
ofs-1 就是长度
Dim b As Byte
Dim ofs As Integer
Dim p As IntPtr = System.Runtime.InteropServices.Marshal.StringToCoTaskMemAnsi(a)
Do
b = System.Runtime.InteropServices.Marshal.ReadByte(p, ofs)
ofs += 1
Loop Until b = 0
MsgBox(ofs - 1)
ofs-1 就是长度
#3
dim str as string="abc李123"
dim strLenth as Integer=System.Text.UnicodeEncoding.Default.GetByteCount(str)
msgbox(strLenth)
dim strLenth as Integer=System.Text.UnicodeEncoding.Default.GetByteCount(str)
msgbox(strLenth)
#4
string str="abc李123";
int strlength = str.length;
MessageBox.Show(strlength.ToString());
#5
解决办法如下,str为要检测的字符串:
ASCIIEncoding n = new ASCIIEncoding();
byte[] b = n.GetBytes(str);
int l = 0; // l 为字符串之实际长度
for (int i=0;i <= b.Length-1;i++)
{
if (b[i] ==63) //判断是否为汉字或全脚符号
{
l++;
}
l++;
}
------------------------------------------------------------------------
马上要升星星了,请都给分 ,争取不穿裤衩过年 :^_^
ASCIIEncoding n = new ASCIIEncoding();
byte[] b = n.GetBytes(str);
int l = 0; // l 为字符串之实际长度
for (int i=0;i <= b.Length-1;i++)
{
if (b[i] ==63) //判断是否为汉字或全脚符号
{
l++;
}
l++;
}
------------------------------------------------------------------------
马上要升星星了,请都给分 ,争取不穿裤衩过年 :^_^
#6
System.Text.Encoding.GetEncoding("GB2312").GetByteCount("abc李123")