Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 280893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:09:26+00:00 2026-05-12T05:09:26+00:00

I have the following string with separate delimiters that needs to be parsed out

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:09:26+00:00Added an answer on May 12, 2026 at 5:09 am

    Your algorithm is basically right. The problem is that String.split() works with regexes as the input, not a string. So “||” does not mean the String “||”, it means whatever the regex means. So replace this:

    subGroupArray[counter].split("||");
    

    With:

    subGroupArray[counter].split("\\|\\|");
    

    And it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following URL string /category/category1/2010/12/10/id I need to separate string into parts. I'm
I have a command line application that needs to support arguments of the following
i have the following string: http://pastebin.com/d29ae565b i need to separate each value and put
here is my problem I have the following array (for example) string[] arr =
I have a variable named String that may have values like the following ones:
I have the following PHP code and would like to split the string into
Quick question, I have the following string which is a coma separated list of
I have following string: Test, User < test@test.com >, Another, Test < another@test.com >,
I have following situation: String a = A Web crawler is a computer program
I have the following string arrays: var myArray1 = new string[] {A, B, C};

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.