Results 1 to 7 of 7

Thread: °C showing up as °C

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    6

    °C showing up as °C

    I've written a program to read an rss feed for the weather and save the temperature into a text file, but when i view the text file in notepad it looks great eg. 14°C but when i view it under MS Word or Word Pad its coming up as 14°C.

    Any ideas how to get rid of that  ?

    If i need to post the code let me know, or if need any more info.

    Thanks.

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: °C showing up as °C

    Show the line of code that is responsible for adding the degrees character.
    I don't live here any more.

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    6

    Re: °C showing up as °C

    I'll post the whole code.

    Code:
    System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
    
    			xml.Load("http://www.wunderground.com/auto/rss_full/global/stations/94821.xml");
    
    			System.Xml.XmlNode weather = xml.SelectSingleNode("/rss/channel/item/description");
    
    			string tempF = null;
    			string tempC = null;
    
    			if (weather != null)
    			{
    				string[] tokens = weather.InnerText.Split(" ".ToCharArray());
        
    				tempF = tokens[1];
    				tempC = tokens[3];
    			}
    
    			Console.WriteLine("Temperature F: " + tempF);
    			Console.WriteLine("Temperature C: " + tempC);
    			System.IO.StreamWriter sw = new System.IO.StreamWriter(@"c:\weather.txt", false);
    			sw.WriteLine(tempC);
    			sw.Close();
    			sw = null;

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: °C showing up as °C

    So basically you are fetching the "°C" directly from the website's data stream.

    Since "°" is a special character its likely that the "Â" is a prefix that identifies it as such. All you need to do is strip out the "Â" OR manually insert "°C" yourself.

    Thre are numerous string functions available to handle this.
    I don't live here any more.

  5. #5
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Re: °C showing up as °C

    just specify System.Text.Encoding.UTF8 in your StreamWriter. eg:
    VB Code:
    1. System.IO.StreamWriter sw = new System.IO.StreamWriter(@"c:\weather.txt", false,[B]System.Text.Encoding.UTF8[/B]);
    2.     sw.WriteLine(tempC);
    3.     sw.Close();
    4.     sw = null;
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  6. #6
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: °C showing up as °C

    Quote Originally Posted by wossname
    So basically you are fetching the "°C" directly from the website's data stream.

    Since "°" is a special character its likely that the "Â" is a prefix that identifies it as such. All you need to do is strip out the "Â" OR manually insert "°C" yourself.

    Thre are numerous string functions available to handle this.
    shut up you're wrong

    listen to what dynamic_sysop said
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    6

    Re: °C showing up as °C

    thanks for this, i'll give it ago soon!

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