Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to handle special International characters in C#.

How to handle special International characters in C#.

Scheduled Pinned Locked Moved C#
questioncsharphelptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MinhajuddinK
    wrote on last edited by
    #1

    Hi all, I have written a small piece of code which splits a text file into "N" number of output files with "X" records each. The code is working fine, But it is unable to handle special characters. When the input file has text like --> "INDUSTRIESTRAßE" It's converting it to --> "INDUSTRIESTRA?E". I have not included any provision to handle the special characters. How can I change the code so that it doesn't misinterpret these special characters while splitting a file. This is the code which reads and writes the data.

                using (StreamReader sr = new StreamReader(input\_file\_path + "\\\\" + input\_file\_name))
                {
                    if (firstLineColumns)
                        header = sr.ReadLine();
                        //Ignore the first line if the first line is columns
                    while (!sr.EndOfStream)
                    {
                        fs = new FileStream(target\_path + "\\\\" + target\_file\_pattern + file\_no.ToString() + extension, FileMode.Create);
                        sw = new StreamWriter(fs);
                        if (targetFirstLineColumns)
                            sw.WriteLine(header);
                        for (int i = 0; i < number\_of\_lines\_per\_file && !sr.EndOfStream; i++)
                        {
                            sw.WriteLine(sr.ReadLine());
                        }
                        sw.Close();
                        fs.Close();
                        file\_no++;
                    }
                }
    

    Here I want to split the input to "N" number of files with the "X" number of lines each. Please help me out here. Thank you very much! You don't have to be AFRAID!

    M 1 Reply Last reply
    0
    • M MinhajuddinK

      Hi all, I have written a small piece of code which splits a text file into "N" number of output files with "X" records each. The code is working fine, But it is unable to handle special characters. When the input file has text like --> "INDUSTRIESTRAßE" It's converting it to --> "INDUSTRIESTRA?E". I have not included any provision to handle the special characters. How can I change the code so that it doesn't misinterpret these special characters while splitting a file. This is the code which reads and writes the data.

                  using (StreamReader sr = new StreamReader(input\_file\_path + "\\\\" + input\_file\_name))
                  {
                      if (firstLineColumns)
                          header = sr.ReadLine();
                          //Ignore the first line if the first line is columns
                      while (!sr.EndOfStream)
                      {
                          fs = new FileStream(target\_path + "\\\\" + target\_file\_pattern + file\_no.ToString() + extension, FileMode.Create);
                          sw = new StreamWriter(fs);
                          if (targetFirstLineColumns)
                              sw.WriteLine(header);
                          for (int i = 0; i < number\_of\_lines\_per\_file && !sr.EndOfStream; i++)
                          {
                              sw.WriteLine(sr.ReadLine());
                          }
                          sw.Close();
                          fs.Close();
                          file\_no++;
                      }
                  }
      

      Here I want to split the input to "N" number of files with the "X" number of lines each. Please help me out here. Thank you very much! You don't have to be AFRAID!

      M Offline
      M Offline
      Matthew Butler 0
      wrote on last edited by
      #2

      Hi, When using StreamReader and StreamWriter you need to set a character Encoding:

      ... StreamReader sr = new StreamReader(input_file_path + "\\" + input_file_name, Encoding.Unicode) ...

      (and the same for the writer). There are other encoding formats aswell. Hope this helps.

      Matthew Butler

      M 1 Reply Last reply
      0
      • M Matthew Butler 0

        Hi, When using StreamReader and StreamWriter you need to set a character Encoding:

        ... StreamReader sr = new StreamReader(input_file_path + "\\" + input_file_name, Encoding.Unicode) ...

        (and the same for the writer). There are other encoding formats aswell. Hope this helps.

        Matthew Butler

        M Offline
        M Offline
        MinhajuddinK
        wrote on last edited by
        #3

        Thank you for your information. I'll try that and get back to you.

        You don't have to be AFRAID!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups