//js方法
new function(s)
{
if(!arguments.length||!s) return null;
if(""==s)
return 0;
var
l=0;
for(var
i=0;i
{
if(s.charCodeAt(i)>255) l+=2;
else l++;
}
alert(l);
}("hello你好!");
//.net 函数
//.net 支持的编码
ASCII编码 System.Text.ASCIIEncoding 将字符与 ASCII 字符相互转换。
多种编码 System.Text.Encoding 将字符与 Convert 方法中指定的各种编码相互转换。
UTF-16 Unicode 编码 System.Text.UnicodeEncoding 在其他编码与 UTF-16 编码之间进行转换。此方案将字符表示为 16 位整数。
UTF-8 Unicode 编码 System.Text.UTF8Encoding 在其他编码与 UTF-8 编码之间进行转换。此宽度可变编码方案用一至四个字节表示字符。
//.net 获取字符字节数的函数
System.Text.Encoding.Default.GetByteCount("中国人abc")//6
MessageBox.Show(System.Text.Encoding.GetEncoding("GB2312").GetBytes("中国人abc").Length+"");//9
MessageBox.Show(System.Text.Encoding.GetEncoding("ASCII").GetBytes("中国人abc").Length
+ "");//6
MessageBox.Show(System.Text.Encoding.GetEncoding("UTF-16").GetBytes("中国人abc").Length
+ "");//12
MessageBox.Show(System.Text.Encoding.GetEncoding("UTF-8").GetBytes("中国人abc").Length
+ "");//12
//Oracle 函数
select lengthb('中国人abc') vchar字节,lengthb(n'中国人abc') nchar字节,
length('中国人abc') vchar长度,length(n'中国人abc') nchar长度 from dual;