How to display special characters from a csv document ?

edited October 2014 in How To...

Hello everyone,

I'm trying to display special characters on the screen, usually it's not really an issue :

if I type :

text("àéèâ",50,50);

it gets displayed right but when I try to get a String from a csv that's another story, and every accentued character gets buggy.

Is it possible to set up how string are processed with processing ? I guess it detected from my system's language otherewise the example above would display gibberish right ?

Here is some code :

Table blanc;
color c;

int row_index;

void setup() {

  size(800, 400);

  blanc = loadTable("blanc.csv", "header");
  println(blanc.getRowCount() + " total rows in table"); 

  row_index = 0;
  textSize(20);
}



void draw() {

  String newColor = blanc.getString(row_index, 2);
  c = color(unhex(newColor));

  background(c);
  fill(0);

  text((blanc.getString(row_index, 0)), 50, 50);
  text(blanc.getString(row_index, 1), 50, 100);
}


void keyReleased() {
  if (key == CODED) {
    if ( keyCode == LEFT) {
      row_index --;
    } else if ( keyCode == RIGHT) {
      row_index ++;
    }
  }
  if ( row_index > blanc.getRowCount()-1) row_index = 0;
  else if (row_index < 0) row_index = blanc.getRowCount()-1;
}

and here's an example of csv :

 name,def, code
albâtre,[~ d'~] (inv) Blanc translucide et éclatant,FEFEFE,
argent,[blanc d'~] (inv) pigment. Synonyme de blanc de céruse,FEFEFE,
argile,(inv) Généralement blanc grisâtre. Mais peut également correspondre à une teinte crème ocre pâle voire pêche grisâtre ou coquille d'oeuf.,EFEFEF,
blanc,Couleur de la neige des nuages du coton du lait.,F9F9F9,
cassé,[blanc ~] (inv) Blanc tirant sur le jaune ou le gris.,FEFEE2,
céruse,[blanc de ~] (inv) pigment. Blanc.,FEFEFE,
chenu,Blanc blanchi.,FEFEFE,
Chine,[blanc de ~] (inv) Blanc pur.,FEFEFE, 
coquille d'oeuf,(inv) Blanc légèrement beige-rosé.,FDE9E0, 
crème,[~ blanc ~] (inv) Blanc légèrement teinté de jaune.,FDF1B8,
écru,Blanc légèrement teinté de jaune. Couleur de la toile non blanchie.,FEFEE0,
Espagne,[blanc d'~] (inv) pigment. Blanc légèrement crème.,FEFDF0,
ivoire,[~ d'~] (inv) Blanc laiteux ou très légèrement gris-jaunâtre comme le vieil ivoire patiné.,FFFFD4,
lait,[blanc de ~ de ~] (inv) Blanc de la couleur du lait.,FBFCFA     ,
lunaire,[blanc ~] (inv) Blanc tirant légèrement sur un bleu froid.,F4FEFE,  
Meudon,[blanc de ~] (inv) Synonyme de blanc d'Espagne,FEFDF0,
neige,[~ blanc ~] (inv) Blanc pur et éclatant comme la neige.,FEFEFE, 
opalin,Qui a une teinte laiteuse et bleuâtre avec des reflets irisés.,F2FFFF,   
platine,(inv) Blond extrèmement pâle à blanc argenté.,FAF0C5,
plomb,[blanc de ~] (inv) Synonyme de blanc de céruse,FEFEFE,
Troyes,[blanc de ~] (inv) pigment. Synonyme de blanc d'Espagne,FEFDF0, 
zinc,[blanc de ~] (inv) pigment. Blanc légèrement bleuâtre.,F6FEFE,

Answers

  • edited October 2014 Answer ✓

    Your code worked well here except this line: "lait,[blanc de ~ de ~] (inv) Blanc de la couleur du lait.,FBFCFA ,"!
    You gotta trim out those empty spaces between "FBFCFA" & "," there! :-&

    I believe that b/c I've saved that text using a Linux app; which by default is encoded in UTF8 & LF, made it very compatible w/ Processing's loadTable()! *-:)

    If you're in Windows, I highly recommend Notepad2.
    You just need to configure it to save in UTF-8 and ending lines w/ LF! ;)

  • Thanks ! you are right, it was just encoding options :)

    right for the empty spaces , did that manually and missed one .

    thanks again

  • LF vs. CF/LF shouldn't be an issue, though.

  • edited October 2014
    • Unix: LF
    • Mac: CR (I guess)
    • Win: CR + LF
  • CR for Mac was for MacOS before X. X being Unix-based, it uses LF now.

    By "shouldn't be an issue", I mean good libraries / softwares can now handle smartly any end-of-line character sequence. Windows' Notepad being a notorious exception... :-)

Sign In or Register to comment.