Le code
String texte = "This is an example sentence. Can sentences also be terminated "+ "with a questionmark? Sometimes punctuation does not terminate "+ "a sentence, e.g. when abbreviating.";
// Expression provenant de http://www.codeproject.com/KB/vb/SentenceParserVB.aspx
// adapté par Jo Wood, London
void setup(){
size(200,100);
}
void draw(){
String[] phrases = texte.split("(?<=['\"\"A-Za-z0-9][\\.\\!\\?])\\s+(?=[A-Z])");
// usage spécial de la boucle : parcourir l'array phrases
for (String phrase : phrases){
println(phrase);
delay(1000);
}
}
Une version permettant de faire le même travail à partir d’un fichier joint (ne pas oublier, du coup, de mettre ce fichier "montexte.txt" dans le dossier du sketch) :
String texte;
// Expression provenant de http://www.codeproject.com/KB/vb/SentenceParserVB.aspx
void setup(){
size(200,100);
// on importe un texte depuis un fichier txt
String[] importer=loadStrings("montexte.txt");
// on assemble les lignes de textes,
// qui ne correspondent pas nécessairement à des phrases
texte=join(importer, " ");
}
void draw(){
String[] phrases = texte.split("(?<=['\"\"A-Za-z0-9][\\.\\!\\?])\\s+(?=[A-Z])");
// usage spécial de la boucle : parcourir l'array phrases
for (String phrase : phrases){
println(phrase);
delay(1000);
}
}