How to get rid of mysterious  char

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oveshot16
    New Member
    • Apr 2009
    • 2

    How to get rid of mysterious  char

    When I am writing the degree symbol to a text document using the streamwriter it shows up with a Mysterious  in front of it. I know this has something to do with its encoding but I am new to encoding in general and Have no idea how to work it. here is my code

    Code:
    StreamWriter sw2;
    sw2 = File.CreateText("DB\\ioSys.FIL");
    string  DegreeC = "°C";
    
    IO_file = "t_01_0" + CBA41G1Bus.Text + "_" + StartAddress1 + "_" + temp + "\t" + temp + ".000000\t0\t"+ DegreeC";
    
    sw2.WriteLine(IO_file);
    Any ideas? Thanks
  • oveshot16
    New Member
    • Apr 2009
    • 2

    #2
    In case anyone stumble upon this, after much searching I have found a fix for this problem even thoughI don't know exactly how it works

    I changed my code to look like this

    Code:
    StreamWriter sw2= new StreamWriter("Devices.FIL", true, Encoding.GetEncoding("ISO-8859-15")); 
    
    string  DegreeC = "°C"; 
      
    IO_file = "t_01_0" + CBA41G1Bus.Text + "_" + StartAddress1 + "_" + temp + "\t" + temp + ".000000\t0\t"+ DegreeC"; 
      
    sw2.WriteLine(IO_file);
    this code would not work correctly with ASCII, UTF7, UTF32, or its default UTF8

    In ASCII it replace the degree symbol with question marks.

    Oddly it did work with UNICODE but the program I am making this file for doesn't read it so it was pointless.

    this ISO was the only thing that made it all functional
    Last edited by PRR; Apr 10 '09, 04:35 AM. Reason: Please post code in [code] [/code] tags.

    Comment

    • PRR
      Recognized Expert Contributor
      • Dec 2007
      • 750

      #3
      Specifying encoding is a must...speciall y when you need to transfer/share file

      Comment

      • sramey
        New Member
        • Aug 2009
        • 1

        #4
        This was awesome, helped me fix a problem I couldn't figure out. Thanks!

        Comment

        • nojiratz
          New Member
          • Feb 2016
          • 1

          #5
          Worked for me! Thx for your post!

          Comment

          Working...