如何将一个Unicode的汉字转换成Ascii编码??“手”--〉手

zhongkeruanjian 2006-07-19 03:25:34
在C#
比如将“手”字转换成手

最关键的是如果将“手”转换成25163这五位数字???
...全文
461 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhongkeruanjian 2006-07-19
  • 打赏
  • 举报
回复
哈,两颗星并不表示水平高,只是热心而已。QP是什么东东??
ncjcz 2006-07-19
  • 打赏
  • 举报
回复
jf
tcx1986 2006-07-19
  • 打赏
  • 举报
回复
有没达人能给段QP解码的代码啊
我用jmail做邮件接受出现了QP乱码
对这东东是一窍不通啊
头疼啊
TryToday 2006-07-19
  • 打赏
  • 举报
回复
两颗红星了还搞不定啊:)
接点分
代码蜗牛sky 2006-07-19
  • 打赏
  • 举报
回复
是的,这个对中文的编码转换是有点问题,所以才说要改改

既然你已经把问题解决了,那就算了
zhongkeruanjian 2006-07-19
  • 打赏
  • 举报
回复
misvcom(零下一度) 这个不行,我试过了,最后是?????
代码蜗牛sky 2006-07-19
  • 打赏
  • 举报
回复
拿下面这个改改就行了

string unicodeString = "This string contains the unicode character Pi(\u03a0)";

// Create two different encodings.
Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;

// Convert the string into a byte[].
byte[] unicodeBytes = unicode.GetBytes(unicodeString);

// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);

// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string asciiString = new string(asciiChars);

// Display the strings created before and after the conversion.
Console.WriteLine("Original string: {0}", unicodeString);
Console.WriteLine("Ascii converted string: {0}", asciiString);
huigll 2006-07-19
  • 打赏
  • 举报
回复
o ?自己搞定了?
zhongkeruanjian 2006-07-19
  • 打赏
  • 举报
回复
有了一个:(没有人回,请回一个来拿分
public static string GetAsciiFromUnicode(string unicodeString)
{
char[] chars = unicodeString.ToCharArray();
string asciiString = string.Empty;
foreach (char code in chars)
{
asciiString += "&#" + (Math.Abs((int)code)).ToString()+";";
}
return asciiString;
}

110,500

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧