日期:2014-05-19  浏览次数:21055 次

再问UTF8,知道U8的编码,怎么得到它对应的字符?
有这样一张表,想通过前面的U8代码得到字符,与第二列对比防止错误,有啥好办法没?
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
------解决方案--------------------
UTF8Encoding e = new UTF8Encoding();
e.GetString(你要转化的byte[]); //这个用来解码,返回一个string
e.GetByte(string s); // 这个用来编码,返回byte[]
------解决方案--------------------
直接定义!~
char c= '\u30E0 ' //ム
这是unicode 码! 相信你是从windows 文字code表里找的!~
呵呵!~~

------解决方案--------------------
转成Char型
char ch = '\u30E0 ';
MessageBox.Show(ch.ToString());
------解决方案--------------------
//将UTF-8编码转换成字符串
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());
}

------解决方案--------------------
// 数据库存的是字符串 ?

char ch = (char)byte.Parse(dr[1].ToString(), NumberStyles.AllowHexSpecifier);
------解决方案--------------------
// OR
char ch = (char)byte.Parse( "0x " + dr[1].ToString());
------解决方案--------------------
不懂,帮顶
------解决方案--------------------
试试这样

int n = int.Parse( "30E0 ", System.Globalization.NumberStyles.AllowHexSpecifier); // 转为整型,这样不会溢出了