当前位置: 移动技术网 > IT编程>开发语言>c# > c#字符长度查询代码

c#字符长度查询代码

2019年07月18日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下: using system; using system.text; namespace stringlengthtest { class program
复制代码 代码如下:

using system;
using system.text;
namespace stringlengthtest
{
class program
{
static void main(string[] args)
{
string strtmp = "abcd1234软件包";
int i = encoding.getencoding("gb2312").getbytes(strtmp).length;
int j = encoding.unicode.getbytes(strtmp).length;
int m = encoding.ascii.getbytes(strtmp).length;
int n = encoding.default.getbytes(strtmp).length;
int k = encoding.utf8.getbytes(strtmp).length;
console.writeline(strtmp);
console.writeline("gb2312: " + i);
console.writeline("unicode:" + j);
console.writeline("ascii: " + m);
console.writeline("default:" + n);
console.writeline("utf8: " + k);
console.readkey();
}
}
}

运行结果:

abcd1234软件包
gb2312: 14
unicode:22
ascii: 11
default:14
utf8: 17

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网