ASP.NET-------字符串和字节数组转换
using System;
using System.Collections.Generic;
using System.Text;
namespace NET.MST.Fourth.StringByte
{
class StringByte
{
static void Main(string[] args)
{
String s = "我是字符串,I am string";
//字节数组转换到字符串
Byte[] utf8 = StringToByte(s,
Encoding.UTF8);
Byte[] gb2312 = StringToByte(s,
Encoding.GetEncoding("GB2312"));
Byte[] unicode = StringToByte(s,
Encoding.Unicode);
Console.WriteLine(utf8.Length);
Console.WriteLine(gb2312.Length);
Console.WriteLine(unicode.Length);
//转换回字符串
Console.WriteLine(ByteToString(utf8,
Encoding.UTF8));
Console.WriteLine(ByteToString(gb2312,
Encoding.GetEncoding("GB2312")));
Console.WriteLine(ByteToString(unicode,
Encoding.Unicode));
Console.Read();
}
static Byte[] StringToByte(String s, Encoding encoding)
{
return encoding.GetBytes(s);
}
static String ByteToString(Byte[] b, Encoding encoding)
{
return encoding.GetString(b);
}
}
}
ASP.NET-------字符串和字节数组转换
热推产品
- ActiveReport... 强大的.NET报表设计、浏览、打印、转换控件,可以同时用于WindowsForms谀坔攀戀Forms平台下......
- AnyChart AnyChart使你可以创建出绚丽的交互式的Flash和HTML5的图表和仪表控件。可以用于仪表盘的创......
推荐产品