Loadstrings with Umlauts Umlaut Umlaute / CSV from Excel

Hello all,

I am loading / loadstrings a CSV with swedish Umlauts

öå

They don’t come out right - What can I do?


 // -------------------------------------------------------------------------------------------
  // load articles section 

  void loadArticles() {
    //
    String name1 = "Example articles 1.csv";
    String[] loadData = loadStrings(name1);

    valuesArray1 = new JSONArray();

    int i=0; 
    for (String s1 : loadData) {

      if (s1.equals("Art nr;Description;Type"))
        continue;

      String[] s2 = split(s1, ";"); 

      JSONObject article = new JSONObject();

      article.setString("id", s2[0]);
      article.setString("article", s2[1]);
      article.setString("articleType", s2[2]);

      valuesArray1.setJSONObject(i, article);
      i++;
    }//for
  }//func

  // -------------------------------------------------------------------------------------------
2 Likes

I am on a Win 10 machine

The data is from xlsx and I export from Excel as csv

The csv comes out correct when I look at it in notepad

I also tried loadTable instead of loadStrings

1 Like

Have you checked whether “Example articles 1.csv” is indeed saved as UTF-8 encoding? :thinking:

2 Likes

on a Win 10 / 64b / region US /

String swedish = "1,2,3,4,5,a,A,Å,å,Ä,ä,o,O,Ö,ö";
String[] lines;
String outfile = "data/test.csv"; 

void setup() {
  size(100,200);
  makeFile();
  loadFile();
}
void draw() {
}

void makeFile() {
  lines = swedish.split(",");
  saveStrings(outfile, lines);
  println("save to "+outfile);
}

Table data;

void loadFile() {
  int dy =0;
  data = loadTable(outfile,"csv");
  println(data.getRowCount() + " rows, "+data.getColumnCount() + " cols in table");
  for (TableRow row : data.rows())   text( row.getString(0) ,10,10+13*dy++);
}

/* data/test.csv
1
2
3
4
5
a
A
Å
å
Ä
ä
o
O
Ö
ö
*/

2 Likes

@GoToLoop

I tried to tell Excel to export in the right format but I don’t know how to tell it to

How can I?

1 Like

@kll

I know

But I come from excel

Question is what export format do I have to use in excel. I tried a lot of them though (txt, csv, tsv…)

Maybe export as webpage?

2 Likes

test with LIBRE Office
needed language swedish / UTF16
but [SAVE AS] to CSV UTF 8 possible / worked

2 Likes
1 Like

I think I could copy the content in the Sketch and just parse into a Table() right?

Using split ()

1 Like

Will saving your file as a UTF-8 CSV solve your problem, or do you need to make your code able to load non-UTF-8 text?

https://processing.org/reference/loadStrings_.html

Here is an old example of loading iso-8859-2 text:

https://processing.org/discourse/beta/num_1248357556.html

3 Likes

I just hard copied the content into the code of the sketch

1 Like