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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:07:00+00:00 2026-06-11T11:07:00+00:00

Alright so here is my problem. Basically I have a string with 4 words

  • 0

Alright so here is my problem. Basically I have a string with 4 words in it, with each word seperated by a #. What I need to do is use the substring method to extract each word and print it out. I am having trouble figuring out the parameters for it though. I can always get the first one right, but the following ones generally have problems.
Here is the first piece of the code:

word = format.substring( 0 , format.indexOf('#') );

Now from what I understand this basically means start at the beginning of the string, and end right before the #. So using the same logic, I tried to extract the second word like so:

wordTwo = format.substring ( wordlength + 1 , format.indexOf('#') ); 
//The plus one so I don't start at the #.

But with this I continually get errors saying it doesn’t exist. I figured that the compiler was trying to read the first # before the second word, so I rewrote it like so:

wordTwo = format.substring (wordlength + 1, 1 + wordLength + format.indexOf('#') );

And with this it just completely screws it up, either not printing the second word or not stopping in the right place. If I could get any help on the formatting of this, it would be greatly appreciated. Since this is for a class, I am limited to using very basic methods such as indexOf, length, substring etc. so if you could refrain from using anything to complex that would be amazing!

  • 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-06-11T11:07:00+00:00Added an answer on June 11, 2026 at 11:07 am

    If you have to use substring then you need to use the variant of indexOf that takes a start. This means you can start look for the second # by starting the search after the first one. I.e.

    wordTwo = format.substring ( wordlength + 1 , format.indexOf('#', wordlength + 1 ) );
    

    There are however much better ways of splitting a string on a delimiter like this. You can use a StringTokenizer. This is designed for splitting strings like this. Basically:

    StringTokenizer tok = new StringTokenizer(format, "#");
    String word = tok.nextToken();
    String word2 = tok.nextToken();
    String word3 = tok.nextToken();
    

    Or you can use the String.split method which is designed for splitting strings. e.g.

    String[] parts = String.split("#");
    String word = parts[0];
    String word2 = parts[1];
    String word3 = parts[2];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, here is my problem i'm trying to solve. I have an index page
Alright, title is REALLY sloppy. Here's my problem: I have a news site and
alright so i have a small problem here, i have this here. - (void)alertView:(UIAlertView
Alright so pretty basic, here are the pieces of code I have, basically it's
Alright so here is the question. I have a user class which contains a
Alright, so here's my problem. I'm trying to write a script in PHP that
Alright, so heres my problem: I have an application I am working with that
Alright, here we go. I have a cocos2d app, and there are targets that
Alright, so heres my problem, i need my user to be able to upload
I have a very recurrent problem here. (it happens literally all the time). I

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.