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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
package test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Record {
public static void main(String[] args) {
List<String> source = Arrays.asList(
"'RECORD','Produit','Client','VARIABLES','P1','P2','P3','P4','P5','P6','P7',\r\n",
"&'P8','P9','P10','P11','P12','P24','P25','P26','P27','P28','P29','P30','P31',\r\n",
"&'P32','P33','P34','P35'\r\n",
"'NUMERIC 12.0','STRING 12','STRING 12','STRING 12','NUMERIC 19.4',\r\n",
"&'NUMERIC 19.4','NUMERIC 19.4','NUMERIC 19.4','NUMERIC 19.4','NUMERIC 19.4',\r\n",
"&'NUMERIC 19.4','NUMERIC 19.4','NUMERIC 19.4','NUMERIC 19.4','NUMERIC 19.4',\r\n",
"&'NUMERIC 19.4','NUMERIC 19.4','NUMERIC 19.4','NUMERIC 19.4','NUMERIC 19.4',\r\n",
"&'NUMERIC 19.4','NUMERIC 19.4','NUMERIC 19.4','NUMERIC 19.4','NUMERIC 19.4',\r\n",
"&'NUMERIC 19.4','NUMERIC 19.4','NUMERIC 19.4'\r\n",
"1,'PHE','AP','Reel',1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0\r\n",
"2,'PHE','AP','Approuve',1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0\r\n",
"3,'PHE','AP','Coef.Saison',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\r\n"
);
List<String> resultat = new ArrayList<String>();
StringBuilder builder = new StringBuilder();
for (String string : source) {
if (string == null) continue;
if (string.length() == 0) continue;
if (string.charAt(0) != '&') { // nouvelle ligne
if (builder.length() > 0) {
resultat.add( builder.toString() );
builder.setLength(0);
}
} else {
string = string.substring(1); // - '&' initial
}
string = string.replaceAll("\r\n", "");
builder.append( string );
}
// derniere ligne
if (builder.length() > 0) {
resultat.add( builder.toString() );
builder.setLength(0);
}
// resultat
for (String string : resultat) {
System.out.println(string);
}
}
} |
Partager