Encoding Question - print £ in c#

I have text file that I need to ingest.  It contains a sterling sign £.
When I try to print it gets converted to something else.

When writing to the file using streamwrite I tried encoding.default which displays the £ as a ?
When using UTF8 Textpad can't open it.  When I use notepad it shows another weird character.
How can I print a £?
I'm using C# with .NET framework 3.5.
This is a windows rather than a web form.
AlHal2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongCommented:
you need to save the text file as utf-8 encoding compatible.

Ref:
StreamWriter Constructor (Stream, Encoding, Int32)
https://msdn.microsoft.com/en-us/library/72d9f8d5%28v=vs.110%29.aspx
0
AlHal2Author Commented:
I'm using the syntax below and am getting the message that the text file contains characters that do not exist in the code page 1252 (ANSI - :LATIN I).  They will be converted to the system default character, if you click OK.
Sure enough the £ gets converted to a ?

StreamWriter sWriter = new StreamWriter(s_m_log_file_name,false,System .Text .Encoding.UTF8,512  );
        IEnumerator itor = v_p_m_messages.GetEnumerator();

        while (itor.MoveNext())
        {
            sWriter.WriteLine(itor.Current.ToString());
        }
        sWriter.Close();

Open in new window

0
AlHal2Author Commented:
When I save the input file as UTF8 I get an extra  next to the £
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

AlHal2Author Commented:
However the output file comes out OK!
is this what you would expect?
0
Ryan ChongCommented:
yes, this is the exactly what I mentioned.

>>StreamWriter sWriter = new StreamWriter(s_m_log_file_name,false,System.Text.Encoding.UTF8,512  );

I tested locally, it works for me as well.
private void button1_Click(object sender, EventArgs e)
        {
            string fileName = txtPath.Text + "\\test.txt";
            string textToAdd = txtContent.Text;
            FileStream fs = null;
            try
            {
                if (System.IO.File.Exists(fileName))
                {
                    System.IO.File.Delete(fileName);
                }
                fs = new FileStream(fileName, FileMode.CreateNew);
                using (StreamWriter writer = new StreamWriter(fs, Encoding.UTF8, 512))
                {
                    writer.Write(textToAdd);
                }
                MessageBox.Show("Done!", "ok", MessageBoxButtons.OK);
            }
            finally
            {
                if (fs != null)
                    fs.Dispose();
            }
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlHal2Author Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.