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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:50:28+00:00 2026-05-23T07:50:28+00:00

I want to separate street, city, state, country, zip code String = Kanaka, Ranchi,

  • 0

I want to separate street, city, state, country, zip code

String = Kanaka, Ranchi, zalkhand, 10001, India

public class Test extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        StringTokenizer st = new StringTokenizer(" Kanaka, Ranchi, zalkhand, 10001, India"); 
        System.out.println("Tokens are seperated");
        int i=0;
        String street,city,state,zipcode,country;
        while(st.hasMoreTokens())
        {

                if(i==0)
                {
                        street = st.nextToken(",");
                   System.out.println("street ="+street);
                   i++;
                }
                else if(i==1)
                {
                       city = st.nextToken(",");
                        System.out.println("city= "+city);
                        i++;
                }
                else if(i==2)
                {
                       state = st.nextToken(",");
                        System.out.println("state ="+state);
                        i++;
                }
                else if(i==3)
                {
                        zipcode = st.nextToken(",");
                        System.out.println("zipcode= "+zipcode);
                            i++;
                }
                else if(i==4)
                {
                        contry = st.nextToken(",");
                        System.out.println("country= "+country);
                        i++;
                }

        }

    }
}

output is :

06-23 09:23:37.070: INFO/System.out(435): street = Kanaka
06-23 09:23:37.080: INFO/System.out(435): city=  Ranchi
06-23 09:23:37.080: INFO/System.out(435): state = zalkhand
06-23 09:23:37.080: INFO/System.out(435): zipcode=  10001
06-23 09:23:37.080: INFO/System.out(435): country=  India

Above code is work fine with String “Kanaka, Ranchi, zalkhand, 10001, India”

My problem is I parse address string from xml which is not good format

ex. 1) "Kanaka, Ranchi, zalkhand, 10001, India"

    2) "Ranchi, zalkhand, 10001, India"   ---> kanaka(street is absent )

output :
06-23 09:23:37.070: INFO/System.out(435): street = Ranchi
06-23 09:23:37.080: INFO/System.out(435): city= zalkhand
06-23 09:23:37.080: INFO/System.out(435): state = 10001
06-23 09:23:37.080: INFO/System.out(435): zipcode= India
06-23 09:23:37.080: INFO/System.out(435): country=

    3) "zalkhand, 10001, India"
    4) Kanaka zalkhand, 10001, India" (, is missing )

like this

so how to separate above string?

  • 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-23T07:50:29+00:00Added an answer on May 23, 2026 at 7:50 am

    You can Create a array and after parsing address String put the tokens in that array using StringTokenizer.But via this you won’t be able to differentiate which is City or ZIP code.
    It is quite difficult so try to make XML well formated.Like if City is absent put a default value so you can use as absent field.

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

Sidebar

Related Questions

I have the simplest code that I want to separate in three files: Header
I have some code within one function that I want to separate into its
I want to separate a string with the occurrence of the Uppercase letters. Suppose
I want to separate my user interface from my code, so I (obviously) landed
I have a string (with spaces) from which i want to separate the last
I have a string 'Merry Christmas'. I want to separate this one as 'Merry'
I am getting string in the following format. ListName|Definition|Answer And How want to separate
I want to separate a string consisting of one or more two-letter codes separated
I know that with a large site you would want to separate footers, menus,
I have a web application that is becoming rather large. I want to separate

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.