在ASP.NET中检测含有中文字符串的实际长度
2005-03-21 20:46
218 查看
以下就是在ASP.NET中检测含有中文字符串的实际长度,这个可能在很多地方都用的上.
VB.NET的写法:
Function StrLength(Byval Str As String) As Integer
Dim En As ASCIIEncoding=New ASCIIEncoding ()
Dim B As Byte()=En.GetBytes(Str)
Dim i As Integer=0
Dim Length As Integer=0
For i=0 To B.Length-1
If B(i)=63 Then
Length+=1
End If
Length+=1
Next
Return Length
End Function
以下是C#的写法:
function int StrLength(string Str)
{
ASCIIEncoding En=new ASCIIEncoding();
Byte[] B=En.GetBytes(Str);
int Length=0;
for(i=0;i<=B.Length-1;i++)
{
if(B==63)
{
Length+=1;
}
Length +=1;
}
return Length;
}
不过以上这段代码会比较慢一些
VB.NET的写法:
Function StrLength(Byval Str As String) As Integer
Dim En As ASCIIEncoding=New ASCIIEncoding ()
Dim B As Byte()=En.GetBytes(Str)
Dim i As Integer=0
Dim Length As Integer=0
For i=0 To B.Length-1
If B(i)=63 Then
Length+=1
End If
Length+=1
Next
Return Length
End Function
以下是C#的写法:
function int StrLength(string Str)
{
ASCIIEncoding En=new ASCIIEncoding();
Byte[] B=En.GetBytes(Str);
int Length=0;
for(i=0;i<=B.Length-1;i++)
{
if(B==63)
{
Length+=1;
}
Length +=1;
}
return Length;
}
不过以上这段代码会比较慢一些
相关文章推荐
- ASP.NET中检测含有中文字符串的实际长度
- ASP.NET中检测含有中文字符串的实际长度
- 检测含有中文字符串的实际长度
- C#检测含有中文字符串的实际长度
- 中检测含有中文字符串的实际长度
- C#检测含有中文字符串的实际长度
- asp.net获得字符串实际长度(包括中文字符)收藏
- 检测含有中文字符串的实际长度
- asp.net获得字符串实际长度(包括中文字符)
- 检测含有中文字符串的实际长度
- 检测含有中文字符串的实际长度
- 检测含有中文字符串的实际长度
- [Asp.Net]按字符串实际长度截取定长字符窜
- java 判断含有中文的字符串的长度
- asp.net下url参数含有中文读取后为乱码
- asp.net 将指定字符串按指定长度进行截取并用其他字符串替换方法
- asp.net 中文字符串提交乱码的解决方法
- asp.net 获取字符串字节长度