rasul moh

rasul moh

  • NA
  • 79
  • 85.4k

spanish word write to text file

Aug 16 2014 1:04 AM
spanish language word write to text file.

I am used UTF8 method and problem to write the spanish word.

eg.
Capacitación Net  ------> input

Capacitación-Net  ------> output

how to solve i am use many method no response.
reply me soon...very urgent


Answers (7)

0
Vulpes

Vulpes

  • 0
  • 96k
  • 2.6m
Aug 16 2014 7:41 AM
Incidentally, how are you viewing the file?

If you're opening it in a browser or an HTML text editor, then try opening it with Notepad instead.

0
rasul moh

rasul moh

  • 0
  • 79
  • 85.4k
Aug 16 2014 6:53 AM
for (int i = 0; i < gvlocal.Rows.Count; ++i)
            {
                Encoding iso = Encoding.GetEncoding("ISO-8859-1");
                Encoding utf8 = Encoding.UTF8;
                byte[] utfBytes = utf8.GetBytes(gvlocal.Rows[i].Cells[0].Text);
                byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
                string msg = iso.GetString(isoBytes);
                string cname = gvlocal.Rows[i].Cells[0].Text;
                string fp = Server.MapPath("localtext/" + txtcfile.Text);
                StreamWriter file = new StreamWriter(fp, true, Encoding.GetEncoding("iso-8859-1"));
                
                file.WriteLine(cname.Replace(" ", "-").ToString(), Encoding.GetEncoding("iso-8859-1"));
                
                file.Close();
            }

i am use this encoding iso-8859-1 or utf 8.
Statically single word write and 
dynamically word will be encode.........reply soon
0
rasul moh

rasul moh

  • 0
  • 79
  • 85.4k
Aug 16 2014 6:27 AM
this not work in c# asp.net. Mr Vulpes


-1
Vulpes

Vulpes

  • 0
  • 96k
  • 2.6m
Aug 16 2014 7:29 AM
I tried your code, Rasul, and also this simplified version:

        string s = "Capacitación Net";   
        Encoding utf8 = Encoding.UTF8;
        byte[] utfBytes = utf8.GetBytes(s);
        string cname = "spanish.txt";
        string fp = Server.MapPath("localtext/" + cname);
        StreamWriter file = new StreamWriter(fp, true, utf8);
        file.WriteLine(s, utf8);
        file.Close();   

but the accented 'o' was written correctly to the file on both occasions.

Are the Spanish words displaying correctly in the gridview?
 
-1
Ankur Jain

Ankur Jain

  • 0
  • 816
  • 184.9k
Aug 16 2014 7:02 AM
Hi!

try like this..

string s = "Capacitación Net";
        File.WriteAllText("spanish.txt", s, System.Text.Encoding.GetEncoding(850));
        string t = File.ReadAllText("spanish.txt", System.Text.Encoding.GetEncoding(850));
       
        MessageBox.Show(t);

Output:Capacitación Net
Please don't forget to mark it as answer if its helpful...
-1
Vulpes

Vulpes

  • 0
  • 96k
  • 2.6m
Aug 16 2014 6:35 AM
What code are you using to write the Spanish word to a text file?

-1
Vulpes

Vulpes

  • 0
  • 96k
  • 2.6m
Aug 16 2014 6:15 AM
This code is working fine for me.

using System;
using System.IO;
using System.Text;

using System.Windows.Forms;

class Test
{
   static void Main()
   {
      string s = "Capacitación Net";
      File.WriteAllText("spanish.txt", s, Encoding.UTF8);
 
      string t = File.ReadAllText("spanish.txt", Encoding.UTF8);
      MessageBox.Show(t);
   }
}

The file is also opening fine in my browser (Google Chrome).

However, it does look like a display problem as &#243; is the HTML or XML symbol for the letter 'ó'.