Dans ce cas, pour chaque chaine, il te faut faire un 2e découpage sur le '/'
Un exemple rapide:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
private static final String CARGO_SEPARATOR = "/";
private static final String FIELDS_SEPARATOR = "\\.";
/**
* @param args
*/
public static void main(String[] args) {
String in = "1234.5678.9.1/258.5/46.987.654";
String[] strings = in.split(FIELDS_SEPARATOR);
for (String string : strings) {
if (string.contains(CARGO_SEPARATOR)) {
handleCargo(string);
} else {
handleSimpleValue(string);
}
}
}
private static void handleCargo(String cargoValue) {
String[] cargoInfos = cargoValue.split(CARGO_SEPARATOR);
System.out.println(String.format("Cargo info found: cargo#%s mass=%s", cargoInfos[0], cargoInfos[1]));
}
private static void handleSimpleValue(String simpleValue) {
System.out.println("Simple value found: " + simpleValue);
} |
Tu obtiens:
Simple value found: 1234
Simple value found: 5678
Simple value found: 9
Cargo info found: cargo#1 mass=258
Cargo info found: cargo#5 mass=46
Simple value found: 987
Simple value found: 654
J'espère que ça t'aidera
Partager