有这样一张表,想通过前面的U8代码得到字符,与第二列对比防止错误,有啥好办法没?
30E0 ム
30E1 メ
30E2 モ
30E3 ャ
30E5 ュ
30E6 ユ
30E7 ョ
30E8 ヨ
30E9 ラ
30EA リ
30EB ル
30EC レ
30ED ロ
30EF ワ
30F3 ン
30E0 ム
30E1 メ
30E2 モ
30E3 ャ
30E5 ュ
30E6 ユ
30E7 ョ
30E8 ヨ
30E9 ラ
30EA リ
30EB ル
30EC レ
30ED ロ
30EF ワ
30F3 ン
朋友 有空就看看这个问题。沒空就算了,謝過了.http://community.csdn.net/Expert/topic/5686/5686047.xml?temp=.8212702
e.GetString(你要转化的byte[]); //这个用来解码,返回一个string
e.GetByte(string s); // 这个用来编码,返回byte[]
char c='\u30E0' //ム
这是unicode 码! 相信你是从windows 文字code表里找的!~
呵呵!~~
char ch = '\u30E0';
MessageBox.Show(ch.ToString());
public string FromUtf8(string str)
{
char[] hexDigits = { '0', '1', '2', '3', '4',
'5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};
List<byte> byteList = new List<byte>(str.Length / 3); if (str != null)
{
List<string> strList = new List<string>();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.Length; ++i)
{
if (str[i] == '%')
{
strList.Add(str.Substring(i, 3));
}
} foreach (string tempStr in strList)
{
int num = 0;
int temp = 0;
for (int j = 0; j < hexDigits.Length; ++j)
{
if (hexDigits[j].Equals(tempStr[1]))
{
temp = j ;
num = temp << 4;
}
} for (int j = 0; j < hexDigits.Length; ++j)
{
if (hexDigits[j].Equals(tempStr[2]))
{
num += j;
}
} byteList.Add((byte)num);
}
} return Encoding.UTF8.GetString(byteList.ToArray());
}
不能用直接连接字符串,有啥方法没?
"\u"+dr[1].ToString();谢谢zhchg6666() ,有空研究一下
char ch = (char)byte.Parse("0x" + dr[1].ToString());
Jinglecat(晓风残月 >> 问题需简洁,错误要详细):你的方法不行啊,提示输入string格式不对(Input string was not in a correct format.)
byte[] bytes = System.BitConverter.GetBytes(n); // 转为字节数组
string str = System.Text.Encoding.UTF8.GetString(bytes); // 转为字符
byte[] bytes = BitConverter.GetBytes(n);
string str = System.Text.Encoding.Unicode.GetString(bytes); // 输出 ム
还有一个小小的问题,str后面正确的字符ム后边多了个/0的字符不知你注意到没有?
嗯,/0似乎不影响啥
0080 €
0081 
0082 ‚
0083 ƒ
0084 „
0085 …
0086 †
0087 ‡
0088 ˆ
0089 ‰
008a Š
008b ‹
008c Œ
008d 
008e Ž
008f 
0090 
0091 ‘
0092 ’
0093 “
0094 ”
0095 •
0096 –
0097 —
0098 ˜
0099 ™
009a š
009b ›
009c œ
009d 
009e ž
009f Ÿ