how to get CodePage?

mc 6,436 Reputation points
2025-12-17T01:46:52.9466667+00:00

var my="slkadjf;as";

how to get its CodePage?

maybe it is korea maybe it is Thai

Developer technologies | .NET | .NET Runtime
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2025-12-17T01:47:03.8066667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To get the CodePage of a string in .NET, you need to first determine the encoding of the string. The CodePage is associated with the encoding used to represent the characters in the string. However, the string itself does not inherently have a CodePage since it is just a sequence of characters.

    If you are working with a specific encoding, you can retrieve its CodePage using the Encoding class. For example:

    using System;
    using System.Text;
    
    class Program
    {
        static void Main()
        {
            // Example string
            var my = "slkadjf;as";
    
            // Get the encoding (e.g., UTF-8)
            Encoding encoding = Encoding.UTF8;
    
            // Get the CodePage
            int codePage = encoding.CodePage;
    
            Console.WriteLine("CodePage: " + codePage);
        }
    }
    

    In this example, you can replace Encoding.UTF8 with the desired encoding (like Encoding.GetEncoding(932) for Japanese or Encoding.GetEncoding(874) for Thai) to get the specific CodePage you are interested in. If you are unsure of the encoding, you may need to analyze the content or context in which the string is used to determine the appropriate encoding.

    0 comments No comments

  2. Susmitha T (INFOSYS LIMITED) 1,875 Reputation points Microsoft External Staff
    2025-12-17T10:04:58.0133333+00:00

    Thank you for reaching out!

    It sounds like you're trying to find out how to get the code page of a certain string you've defined in your code. Here's what you can do:

     

    1. Identify the Encoding: Since your string may contain characters corresponding to different languages (like Korean or Thai), you want to determine the encoding that represents those characters. If you're developing in .NET, you can use the Encoding class to help identify the code page.
    2. Retrieve Code Page Information: You can use the Encoding class to retrieve the code page identifier. For example:
    3. Character Handling: If you're looking to handle specific character encodings, you'll want to select the appropriate Encoding that corresponds to the language. For example:
      • For Korean characters, you might use Encoding.GetEncoding(949).
        • For Thai characters, you might use Encoding.GetEncoding(874).
    var myString = "slkadjf;as"; // Your string
    Encoding encoding = Encoding.Default; // This automatically uses the system-default ANSI code page
    int codePage = encoding.CodePage;
    Console.WriteLine($"The code page for the string is: {codePage}");
    

    If the steps we provided above were not helpful, please let us know your specific concerns so that we can assist you more effectively.

     
    If you find this helpful, Kindly mark the provided solution as "Accept Answer", so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.