Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Parse a Multi-delimited/dimensional String
    primarykey
    data
    text
    <p>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.</p> <p><em>example</em>:</p> <p><strong>category 1---category 2;subgroup 1||subgroup 2---subgroup 1;value 1||value2---value 3</strong></p> <p>I wanted to re-arrange into the following grouping:</p> <p><strong>category 1;subgroup 1;value1;subgroup 2;value 2;category 2;subgroup 1;value1</strong></p> <p>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.<br> each value is associated 1:1 with its subgroup</p> <p>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)</p> <pre><code>StringBuilder result = new StringBuilder(); String categoryArray[] = category.split("---"); String subGroupArray[] = subgroup.split("---"); String valueArray[] = value.split("---"); for (int counter=0; counter&lt;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&lt;subGroupArray2.length;counter2++){ result.append(subGroupArray2[counter2].trim()); result.append(valueArray2[counter2].trim()); } result.append("||"); } return result; </code></pre> <p><br><br> Any help or optimized approaches would certainly be appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload