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 846253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:35:05+00:00 2026-05-15T06:35:05+00:00

I need to split some info from a asterisk delimitted data. Data Format: NAME*ADRESS

  • 0

I need to split some info from a asterisk delimitted data.

Data Format:

NAME*ADRESS LINE1*ADDRESS LINE2

Rules:

1. Name should be always present
2. Address Line 1 and 2 might not be
3. There should be always three asterisks.

Samples:

MR JONES A ORTEGA*ADDRESS 1*ADDRESS2*

Name: MR JONES A ORTEGA
Address Line1: ADDRESS 1
Address Line2: ADDRESS 2

A PAUL*ADDR1**
Name: A PAUL
Address Line1: ADDR1
Address Line2: Not Given

My algo is:

1. Iterate through the characters in the line
2. Store all chars in a temp variables until first * is found. Reject the data if no char is found before first occurence of asterisk. If some chars found, use it as the name.
3. Same as step 2 for finding address line 1 and 2 except that this won't reject the data if no char is found

My algo looks ugly. The code looks uglier. Spliting using //* doesn’t work either since name can be replaced with address line 1 if the data was *Address 1*Address2. Any suggestion?

EDIT:

Try using the data excluding quotes “-MS DEBBIE GREEN*1036 PINEWOOD CRES**”

  • 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-15T06:35:06+00:00Added an answer on May 15, 2026 at 6:35 am

    You can use the String[] split(String regex, int limit) as follows:

        String[] tests = {
            "NAME*ADRESS LINE1*ADDRESS LINE2*",
            "NAME*ADRESS LINE1**",
            "NAME**ADDRESS LINE2*",
            "NAME***",
            "*ADDRESS LINE1*ADDRESS LINE2*",
            "*ADDRESS LINE1**",
            "**ADDRESS LINE2*",
            "***",
            "-MS DEBBIE GREEN*1036 PINEWOOD CRES**",
        };
        for (String test : tests) {
            test = test.substring(0, test.length() - 1);
            String[] parts = test.split("\\*", 3);
            System.out.printf(
                "%s%n  Name: %s%n  Address Line1: %s%n  Address Line2: %s%n%n",
                test, parts[0], parts[1], parts[2]
            );
        }
    

    This prints (as seen on ideone.com):

    NAME*ADRESS LINE1*ADDRESS LINE2*
      Name: NAME
      Address Line1: ADRESS LINE1
      Address Line2: ADDRESS LINE2
    
    NAME*ADRESS LINE1**
      Name: NAME
      Address Line1: ADRESS LINE1
      Address Line2: 
    
    NAME**ADDRESS LINE2*
      Name: NAME
      Address Line1: 
      Address Line2: ADDRESS LINE2
    
    NAME***
      Name: NAME
      Address Line1: 
      Address Line2: 
    
    *ADDRESS LINE1*ADDRESS LINE2*
      Name: 
      Address Line1: ADDRESS LINE1
      Address Line2: ADDRESS LINE2
    
    *ADDRESS LINE1**
      Name: 
      Address Line1: ADDRESS LINE1
      Address Line2: 
    
    **ADDRESS LINE2*
      Name: 
      Address Line1: 
      Address Line2: ADDRESS LINE2
    
    ***
      Name: 
      Address Line1: 
      Address Line2: 
    
    -MS DEBBIE GREEN*1036 PINEWOOD CRES**
      Name: -MS DEBBIE GREEN
      Address Line1: 1036 PINEWOOD CRES
      Address Line2: 
    

    The reason for the "\\*" is because split takes a regular expression, and * is a regex metacharacter, and since you want it to mean literally, it needs to be escaped with a \. Since \ itself is a Java string escape character, to get a \ in a string, you need to double it.

    The reason for the limit of 3 is because you want the array to have 3 parts, including trailing empty strings. A limit-less split discards trailing empty strings by default.

    The last * is discarded manually before the split is performed.

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

Sidebar

Ask A Question

Stats

  • Questions 469k
  • Answers 469k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use namespaces to disambiguate your classes from the classes in… May 16, 2026 at 2:47 am
  • Editorial Team
    Editorial Team added an answer Using .htaccess: RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L] May 16, 2026 at 2:47 am
  • Editorial Team
    Editorial Team added an answer First: there's a simpler way to write _full_categories_list.html.erb using render,… May 16, 2026 at 2:47 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.