• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 631
  • Last Modified:

Special characters and formated text in C#?

I am programming an aplication reading some information from my own web page, I know is not the best code ever done, but this is what I am using, and when I get some special characters like in spanish or french á, é, í, ó, ú or others, so when it is reading a phrase like:


- "más percusión"

It returns like:

- "más percusión"

So when I save some of the info in a DB it save me that with weird chars, not the normal ones.

I am using the Encoding 1252, Any idea to fix the problem?




public string getDocumento_Txtx(string direccion)
        {
            System.Net.WebClient Client = new WebClient();
            Stream strm = null;
            try
            {
                strm = Client.OpenRead(direccion);
            }catch(Exception r)
            {
                if (r.Message.Contains("404"))
                    return "Archivo Inexistente";

            }
            StreamReader sr = new StreamReader(strm,    System.Text.Encoding.GetEncoding(1252));
            string line = "";
            string todo_1 = "";
            do
            {

                line = sr.ReadLine();


                todo_1 = todo_1 + Environment.NewLine + line;

            }
            while (line != null);

            strm.Close();

            return todo_1;

        }

Open in new window

0
rperezretana
Asked:
rperezretana
1 Solution
 
rperezretanaAuthor Commented:
Ok, I found a solution, and this sucks... I paid so much for this answer and someone in ayhoo answers gave me a clue...

I just change the return value for:

return System.Text.Encoding.GetEncoding(1252).GetString(Encoding.GetEncoding(1252).GetBytes(todo_1.ToCharArray()));

And that solved my problem...
return System.Text.Encoding.GetEncoding(1252).GetString(Encoding.GetEncoding(1252).GetBytes(todo_1.ToCharArray()));

Open in new window

0
 
SriVaddadiCommented:
I wonder if you will have to precede your string value with N while storing it in database. i .e. while specifying it as a parameter to your stored proc or even directly in the insert query.

You must precede all Unicode strings with a prefix N when you deal with Unicode string constants in SQL Server

Check this out link as well.

http://msdn.microsoft.com/en-us/library/bb330962(SQL.90).aspx#intlftrql2005_topic2
0
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now