Link to home
Start Free TrialLog in
Avatar of rperezretana
rperezretana

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of rperezretana
rperezretana

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ravi Vaddadi
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