c#字符长度查询代码
程序员文章站
2023-12-01 21:38:40
复制代码 代码如下: 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
上一篇: vue中多个倒计时实现代码实例
下一篇: Vue2.x通用编辑组件的封装及应用详解