求教 有谁会把unicode转utf-8吗
unicode吧
全部回复
仅看楼主
level 1
祁梦mm 楼主
急求
2016年09月17日 11点09分 1
level 2
用Notepad另存?大部分文本编辑器都是用utf-8格式储存的。
2016年09月19日 01点09分 2
level 5
程序我早就写好了,C#
#region 为UTF-8协定作的准备事宜
///<summary>字符原值依照段填满后输出</summary><param name="j">字符U+码</param>
public string CharToJZ2(uint j){string jg="";
if(j>=0&&j<128)jg=Stto.Basex(j.ToString(),10,2).PadLeft(7,'0');
else if(j>=128&&j<0x800){
jg=Stto.Basex(j.ToString(),10,2).PadLeft(11,'0');
}else if(j>=0x800&&j<65536){
jg=Stto.Basex(j.ToString(),10,2).PadLeft(16,'0');
}else if(j>=65536&&j<0x110000){
jg=Stto.Basex(j.ToString(),10,2).PadLeft(21,'0');
}
return jg;
}
///<summary>U+码转UTF-8</summary>
public byte[]YuanToUTF8(uint j){byte[]bytes=new byte[4];
var ei=new string[8];//拼凑出2进制每段
if(j>=0&&j<128){
Array.Resize(ref bytes,1);
bytes[0]=(byte)j;
}else if(j>=128&&j<0x800){
Array.Resize(ref ei,4);Array.Resize(ref bytes,2);
ei[0]=$"110{CharToJZ2(j)[0]}";
ei[1]=CharToJZ2(j).Substring(1,4);
ei[2]=$"10{CharToJZ2(j).Substring(5,2)}";
ei[3]=CharToJZ2(j).Substring(7);
bytes[0]=(byte)(Dp.Finded(Stto.TwoToSixteen(ei[0]),Dp.bas36)*16+Dp.Finded(Stto.TwoToSixteen(ei[1]),Dp.bas36));
}else if(j>=0x800&&j<65536){
Array.Resize(ref ei,6);Array.Resize(ref bytes,3);
ei[0]="1110";
ei[1]=$"{CharToJZ2(j).Substring(0,4)}";
ei[2]=$"10{CharToJZ2(j).Substring(4,2)}";
ei[3]=CharToJZ2(j).Substring(6,4);
ei[4]=$"10{CharToJZ2(j).Substring(10,2)}";
ei[5]=CharToJZ2(j).Substring(12);
bytes[0]=(byte)(Dp.Finded(Stto.TwoToSixteen(ei[0]),Dp.bas36)*16+Dp.Finded(Stto.TwoToSixteen(ei[1]),Dp.bas36));
bytes[1]=(byte)(Dp.Finded(Stto.TwoToSixteen(ei[2]),Dp.bas36)*16+Dp.Finded(Stto.TwoToSixteen(ei[3]),Dp.bas36));
bytes[2]=(byte)(Dp.Finded(Stto.TwoToSixteen(ei[4]),Dp.bas36)*16+Dp.Finded(Stto.TwoToSixteen(ei[5]),Dp.bas36));
}else if(j>=65536&&j<0x110000){
Array.Resize(ref ei,8);Array.Resize(ref bytes,4);
ei[0]="1111";
ei[1]=$"0{CharToJZ2(j).Substring(0,3)}";
ei[2]=$"10{CharToJZ2(j).Substring(3,2)}";
ei[3]=CharToJZ2(j).Substring(5,4);
ei[4]=$"10{CharToJZ2(j).Substring(9,2)}";
ei[5]=CharToJZ2(j).Substring(11,4);
ei[6]=$"10{CharToJZ2(j).Substring(15,2)}";
ei[7]=CharToJZ2(j).Substring(17);
bytes[0]=(byte)(Dp.Finded(Stto.TwoToSixteen(ei[0]),Dp.bas36)*16+Dp.Finded(Stto.TwoToSixteen(ei[1]),Dp.bas36));
bytes[1]=(byte)(Dp.Finded(Stto.TwoToSixteen(ei[2]),Dp.bas36)*16+Dp.Finded(Stto.TwoToSixteen(ei[3]),Dp.bas36));
bytes[2]=(byte)(Dp.Finded(Stto.TwoToSixteen(ei[4]),Dp.bas36)*16+Dp.Finded(Stto.TwoToSixteen(ei[5]),Dp.bas36));
bytes[3]=(byte)(Dp.Finded(Stto.TwoToSixteen(ei[6]),Dp.bas36)*16+Dp.Finded(Stto.TwoToSixteen(ei[7]),Dp.bas36));
}
return bytes;
}
2022年08月21日 02点08分 4
1