开发者

Problem URLDecoding string from ASP to ASP.Net (international characters)

I have a string coming from an ASP page, and I'm trying to URL decode it and display it in an ASP.Net page.

string str = @"%A0%A01stk.+%D8repynt+%3Cbr%3E%A0%A01stk.+Slipsn%E5l+%3Cbr%3E%3Cp%3E+Total+pris%3A+300";

If you look at %D8 it should be translated to the Norwegian character Ø when run through HttpUtility.UrlDecode. But it is not. Depending on what conversion I'm attempting it becomes different things, but never Ø. %E5 should become å.

Here is some conversion code I've been trying out:

public static string Convert(string text)
{
    text = HttpUtility.UrlDecode(text);
    var isoEncoder = System.Text.Encoding.GetEncoding("ISO-8859-1");
    var utf8Encoder = new UTF8Encoding();

    byte[] txtBytes = isoEncoder.GetBytes(text);
    byte[] convertedBytes = System.Text.Encoding.Convert(isoEncoder, System.Text.Encoding.UTF8, txtBytes);

    return utf8Encoder.GetString(convertedBytes);
}

According to Wikipedia article on Ø:

On Microsoft Windows, using the "United States-International" keyboard setting, it can开发者_JAVA技巧 be typed by holding down the Alt-Gr key and pressing "L". It can also be typed under any keyboard setting by holding down the [Alt] key while typing 0216 or 0248 on the numeric keypad, provided the system uses code page 1252 as system default. (Code page 1252 is a superset of ISO 8859-1, and 216 and 248 are the decimal equivalents of hexadecimal D8 and F8.)

This seems to indicate that the input string is correctly formatted (%D8 = Ø).


        string str = @"%A0%A01stk.+%D8repynt+%3Cbr%3E%A0%A01stk.+Slipsn%E5l+%3Cbr%3E%3Cp%3E+Total+pris%3A+300";
        string decoded = System.Web.HttpUtility.UrlDecode(str, System.Text.Encoding.GetEncoding("ISO-8859-1"))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜