0
在開發Windows Phone的過程中,我想編寫一個utf8編碼的URI,但代碼失敗。結果仍然是unicode但不是%D6%DC的形式...如何在WP中將Unicode轉換爲utf8
byte[] unicodeBytes = Encoding.Unicode.GetBytes(str);
byte[] utf8bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, unicodeBytes);
char[] utf8Chars = new char[Encoding.UTF8.GetCharCount(utf8bytes, 0, utf8bytes.Length)];
Encoding.UTF8.GetChars(utf8bytes, 0, utf8bytes.Length, utf8Chars, 0);
string utf8string = new string(utf8Chars);
var URI = new Uri("http://www.jpwy.net/gc/search.php?" + utf8string);
這是怎麼回事?
由於更換上面的代碼。這很方便,很好。我使用的是uri.toString,所以它在輸出中轉換回Unicode。我會採取這個解決方案。 – thsieh 2013-03-10 16:26:26