[英]Decoding in asp.net 4.0 - Special Characters
根據W3C標准在asp.net中解碼特殊字符。 ASCII-URL編碼表。 某些特殊字符未轉換,而是轉換為“?”,請檢查以下問題,%92 ASCII的實際結果是“`”,我正在嘗試實現將其解碼為urlencoding相等字符。
strurl="Workers%92+Accommodation";
string strdecode=Server.UrlDecode(strurl);
例如:ASCII碼%92(按照W3C標准版的url編碼用於'-鍵盤上沒有該編碼,請參考http://www.w3schools.com/TAGS/ref_urlencode.asp )。
嘗試使用此編碼/解碼:
public static string EncodeString(string decodedString)
{
return Convert.ToBase64String(Encoding.UTF8.GetBytes(decodedString));
}
public static string DecodeString(string encodedString)
{
return Encoding.UTF8.GetString(Convert.FromBase64String(encodedString));
}
編輯添加:當您要通過URL傳輸值時,要使用的方法是:HttpServerUtility.UrlTokenEncode()方法
參考: http : //msdn.microsoft.com/zh-cn/library/system.web.httpserverutility.urltokenencode.aspx
您必須使用適當的編碼代碼頁進行解碼。 從http://www.ascii-code.com引用:
8位ASCII表有幾種不同的變體。 下表是根據ISO 8859-1(也稱為ISO Latin-1)制定的。
根據http://en.wikipedia.org/wiki/Windows_code_page,ISO Latin-1的代碼頁為1252
。 要解碼您的字符串,只需執行以下操作:
strurl = Encoding.GetEncoding(1252).
GetString(HttpUtility.UrlDecodeToBytes("%92"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.