I have the following string with separate delimiters that needs to be parsed out and I am running into a bit of a wall at the moment.
example:
category 1---category 2;subgroup 1||subgroup 2---subgroup 1;value 1||value2---value 3
I wanted to re-arrange into the following grouping:
category 1;subgroup 1;value1;subgroup 2;value 2;category 2;subgroup 1;value1
The "---" delimiter separates a category and its values.
The "||" delimiter separates fields belonging to the same category
The ";" delimiter separates the field types (category; subgroup; value)
There can be N categories of which they can have N subgroups.
each value is associated 1:1 with its subgroup
The first pass through works fine but once I hit category 2 everything nulls out. I know I'm missing something obvious but I'm a little hazy right now and Java is not my first language. Here is what I have so far (sans delimiters)
StringBuilder result = new StringBuilder();
String categoryArray[] = category.split("---");
String subGroupArray[] = subgroup.split("---");
String valueArray[] = value.split("---");
for (int counter=0; counter<categoryArray.length;counter++){
String categoryArray2[] = categoryArray[counter].split("\\|\\|");
String subGroupArray2[] = subGroupArray[counter].split("\\|\\|");
String valueArray2[] = valueArray[counter].split("\\|\\|");
result.append(categoryArray[counter].trim());
for (int counter2=0; counter2<subGroupArray2.length;counter2++){
result.append(subGroupArray2[counter2].trim());
result.append(valueArray2[counter2].trim());
}
result.append("||");
}
return result;
Any help or optimized approaches would certainly be appreciated!