1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
// petite méthode ................................
int getCount(JTextArea jta, String rech){
// rech est soit "\n" soit "\n\r"
String tmp = jta.getText();
int compt = 0, index;
while((index = tmp.indexOf(rech)) != -1){
compt++;
tmp = tmp.substring(index + rech.length());
}
tmp = null;
return compt;
}
// ailleurs en appel de la méthode : choisir l'option, 1 normalement
System.out.println("test n : " + getCount(jtaNombres, "\n"));
System.out.println("test nr : " + getCount(jtaNombres, "\n\r")); |
Partager