none
.NET Framework natively supported encodings RRS feed

  • Question

  • Hi, I am looking at this method from Encoding class.

    http://msdn.microsoft.com/en-us/library/wzsz3bk3.aspx

    It mentioned that

    "The GetEncoding method relies on the underlying platform to support most code pages. However, the .NET Framework natively supports some encodings. "

    Where could I find the list of encodings which are natively supported by .NET?

    I am mostly interested in Shift-jis encoding (Code page 932). At which instance is this code page not available to me?

    Thanks.

    Friday, July 4, 2014 8:26 AM

Answers

  • The only encoding that is natively supported by .NET framework is UTF-16 (same as VB). That's the code page used to store the internal string data.

    All other locales are supported by the underlying operating system.

    EDIT: If you're asking for the list of locales that you can assume is available anytime, you can look for the static members of System.Text.Encoding (those marked with "S" icon) that returns System.Text.Encoding.

    If you're working on software that uses CJK codepages, I sincerely recommands you to use UTF8 all the time. It'll save you a lot of headache on code page conversion to other systems later.


    Friday, July 4, 2014 8:56 AM
    Answerer

All replies

  • The only encoding that is natively supported by .NET framework is UTF-16 (same as VB). That's the code page used to store the internal string data.

    All other locales are supported by the underlying operating system.

    EDIT: If you're asking for the list of locales that you can assume is available anytime, you can look for the static members of System.Text.Encoding (those marked with "S" icon) that returns System.Text.Encoding.

    If you're working on software that uses CJK codepages, I sincerely recommands you to use UTF8 all the time. It'll save you a lot of headache on code page conversion to other systems later.


    Friday, July 4, 2014 8:56 AM
    Answerer
  • Thanks for the response. I'm sorry for not replying soon, have been busy with other things.

    I actually could not use UTF-8 as it is more of backward compatibility sort of scenario. Unfortunately, legacy codes hard coded the usage of Shift-JIS encoding. So, my code have to guarantee not to allow certain data to reach the legacy part of the system.

    Anyway, I've tried to install an English Windows 7 OS, but I was still able to retrieve code page 932 successfully using encoding class. I am wondering if it will be installed by default even if I did not install Japanese Language.

    Thursday, August 14, 2014 8:34 AM
  • Windows since Vista contains support for all available locale (when the system is released, locale variants keep added to system so there are new supported code page in each new Windows version) by default, just that it might not install the corresponding fonts if you don't made it available as a display language.

    In that case, I'd recommend you to set the "Language for non-Unicode applications" in "Regional Settings" of control panel to Shift-JIS too. This will make the system aware that when it encounters "Yen"(¥) in path, it actually means "Backslash"(\).



    Thursday, August 14, 2014 8:58 AM
    Answerer
  • "Where could I find the list of encodings which are natively supported by .NET?"

    In the documentation of the Encoding class, see the Remarks section.

    "I am mostly interested in Shift-jis encoding (Code page 932). At which instance is this code page not available to me?"

    According to that table that codepage is not supported natively by .NET Framework, it requires OS support. I think the only case where this codepage may not be available is Windows XP/2003. AFAIR on those systems not all codepages were installed by default, you could select which codepage to install somewhere in control panel's regional settings.

    "So, my code have to guarantee not to allow certain data to reach the legacy part of the system."

    But how are you going to do that anyway? .NET's strings are always UTF-16, are you going to encode/decode the strings to ensure that they don't contain non Shitf-JIS characters?

    • Proposed as answer by cheong00Editor Tuesday, August 19, 2014 2:14 AM
    Thursday, August 14, 2014 9:43 AM
    Moderator
  • Great. I always assume code pages other than UTF16LE are supported by the underlying operating system. Thanks for the correction.
    Thursday, August 14, 2014 9:49 AM
    Answerer
  • Thank you very much for this information.

    "But how are you going to do that anyway? .NET's strings are always UTF-16, are you going to encode/decode the strings to ensure that they don't contain non Shitf-JIS characters?"

    The legacy system doesn't care about the underlying OS language, it just assume shift-jis encoding is used. For my application, I have to make sure it always validates using shift-jis encoding for the mean time. As we move along with the releases and replacing the legacy system, we will make it right.

    Tuesday, August 19, 2014 2:01 AM
  • Btw, I think his reply is the actual answer for this thread, would you please mark his reply as answer so it helps other who search in this forum? Thank you.
    Tuesday, August 19, 2014 2:14 AM
    Answerer