CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Text Encoding

  1. #1
    Join Date
    Apr 2005
    Posts
    33

    Text Encoding

    Hello,

    When using File.CreateText() for creating a text file, the Unicode (UTF-8) is used. But I need to create a text file using another encoding (namely, Hebrew-Windows), because the created file is supposed to serve an input to another program which can't deal with Unicode. How can I set the desired encoding?

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Text Encoding

    You have to deal with concrete code page and stream enconding.

    Look at this example for inspiration:
    Code:
    System.IO.FileStream fs = System.IO.File.OpenWrite("file.txt");
    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fs, System.Text.Encoding.GetEncoding(1255)))
    {
    	sw.WriteLine("some text");
    }
    1255 should be hebrew code page. But I cannot check it. I don't know anything from hebrew language.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  3. #3
    Join Date
    Apr 2005
    Posts
    33

    Re: Text Encoding

    Thank you! It works =)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured