Ваша строка s
структурирована в несколько строк, поэтому вам нужно (1) разбить на \n
, (2) пропустить первые 5 строк, (3) разбить каждую строку на \\|
и (4 ) назначать переменные, когда доступны данные. Вот пример кода, который должен дать вам представление
public static void main(String[] args) {
String s =
"Apprenant: User1\n" +
"\n" +
"\n" +
"Temps |Activité |Sous Activité |Action\n" +
"\n" +
"12:32:02 |Demonstration | |\n" +
"\n" +
"12:32:05 |Démonstration |Mémoire centrale |Inialisation\n" +
"\n" +
"12:32:06 |Démonstration | |Chargement\n" +
"\n" +
"12:32:07 |Démonstration | |Inst Suiv\n" +
"\n" +
"12:32:11 |Manipulation |Mémoire centrale |\n" +
"\n" +
"12:32:15 |Manipulation |Unité de commande |\n" +
"\n" +
"12:32:17 |Manipulation |Mémoire centrale |\n" +
"\n" +
"12:32:20 |Manipulation |Mémoire centrale |Vider la mémoire\n";
String[] rows = s.split("\n");
for (int i = 5; i < rows.length; i++) {
String[] sections = rows[i].split("\\|");
if (sections.length > 1) {
String a = sections[0].trim();
String b = "";
String c = "";
String d = "";
if (sections.length == 2)
b = sections[1].trim();
if (sections.length == 3);
c = sections[2].trim();
if (sections.length == 4)
d = sections[3].trim();
System.out.println("a = " + a + "; b = " + b +
"; c = " + c + "; d = " + d);
}
}
}
и это дает следующий вывод:
a = 12:32:02; b = ; c = ; d =
a = 12:32:05; b = ; c = Mémoire centrale; d = Inialisation
a = 12:32:06; b = ; c = ; d = Chargement
a = 12:32:07; b = ; c = ; d = Inst Suiv
a = 12:32:11; b = ; c = Mémoire centrale; d =
a = 12:32:15; b = ; c = Unité de commande; d =
a = 12:32:17; b = ; c = Mémoire centrale; d =
a = 12:32:20; b = ; c = Mémoire centrale; d = Vider la mémoire