Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write Arabic, Hebrew Into CSV file? [closed]

I can't write to Results.csv any of the languages Arabic or Hebrew, except English. Each time I'm trying to write any one of them I'm getting gibberish marks, in the CSV file where it should have proper Arabic or Hebrew words instead.

I've been trying to use UTF8Encoding, but I'm obviously doing something wrong.

Please take a look and try to correct me:

private void WriteToCsvFile()
{
    var us = users.ElementAt(0);
    string titlenames = "number,";
    string userAnswer = (us.userName + ",");
    foreach (string ss in List)
    {
        // Do stuff
    }
    foreach (string ans in us.answer)
    {
        // Do stuff
    }
    using (StreamWriter sw = new StreamWriter("Results.csv", true, Encoding.UTF8))
    {
        sw.WriteLine(titlenames);
        sw.WriteLine(userAnswer);
    }
    this.Close();
}

Thank you for your time and help!

Here is the CSV file with different kinds of Encoding:

number  לוי  סל    רמי  שופר    ×ב×לה    ×‘×•×   ללונה  פ×רק
22  FALSE   TRUE    FALSE   FALSE   TRUE    TRUE    FALSE   FALSE

number  לוי  סל    רמי  שופר    ×ב×לה    ×‘×•×   ללונה  פ×רק
33  TRUE    TRUE    FALSE   FALSE   FALSE   FALSE   TRUE    FALSE

number  +BdwF1QXZ-  +BeEF3A-    +BegF3gXZ-  +BekF1QXkBeg-   +BdAF0QXQBdwF1A-    +BdEF1QXQ-  +BdwF3AXVBeAF1A-    +BeQF0AXoBec-
22  FALSE   FALSE   FALSE   TRUE    TRUE    TRUE    FALSE   TRUE

number  ÜÕÙ áÜ  èÞÙ éÕäè    ÐÑÐÜÔ   ÑÕÐ ÜÜÕàÔ   äÐèç
33  TRUE    TRUE    FALSE   TRUE    FALSE   TRUE    TRUE    FALSE

number  ÜÕÙ áÜ  èÞÙ éÕäè    ÐÑÐÜÔ   ÑÕÐ ÜÜÕàÔ   äÐèç
44  not answered    not answered    FALSE   not answered    not answered    not answered    not answered    not answered

number  ??? ??  ??? ????    ?????   ??? ?????   ????
55  not answered    not answered    not answered    not answered    not answered    not answered    not answered    not answered

As you can see, gibbrish marks should be names in Arabic and Hebrew.

like image 244
Roy Doron Avatar asked Dec 16 '12 00:12

Roy Doron


People also ask

Does CSV support UTF-8?

and CSV files. Simple CSV files do not support Unicode/UTF-8 characters. This is a limitation of the CSV format and not something that can be changed in DEAR. However, it is possible to import/export Unicode characters following these steps.


1 Answers

You say you are getting "gibberish marks" in your CSV file. That is not because you are writing using the wrong encoding, but that is (most likely) because you are viewing it using the wrong encoding.

Try opening the CSV file using a text editor like Notepad+. Select in the Encoding menu UTF8. You should be seeing the correct characters now. If not, please attach an example CSV file you created with the above code, maybe I can see what goes wrong.

like image 179
Abel Avatar answered Sep 17 '22 02:09

Abel