This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Removing substrings from strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Removing substrings from strings" Watch "Removing substrings from strings" New topic
Author

Removing substrings from strings

Brandon Peeples
Ranch Hand

Joined: Jan 06, 2010
Posts: 38
I am having problems with an assignment where I have to remove a substring from a string. I know I have to make a loop to go through the String, use substring() to remove the substring, indexOf() to find the index to end and resume the String, and an if / else statement to tell whether or not to remove the substring. The problem I am having having my String produce output in the console. When I run my program I can't get the text to show up.

Edit: Found the solution to my problem. Here is my final code:



All advice and guidance appreciated. Thanks.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Ok lets see



should work ...

edit: maybe you should use a StringBuilder especially if you work with longer texts and use this method a lot.


JDBCSupport - An easy to use, light-weight JDBC framework -
Brandon Peeples
Ranch Hand

Joined: Jan 06, 2010
Posts: 38
Thanks for your help Sebastian. I figured out where I made my error.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

Brandon Peeples wrote:Thanks for your help Sebastian. I figured out where I made my error.


Brandon,

Please keep in mind that the forums are used by people to search for help too. If you delete the original question, you basically leave the topic useless. It can't help others.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Brandon Peeples
Ranch Hand

Joined: Jan 06, 2010
Posts: 38
You are right Henry. I'll repost my original question. Thanks.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

Brandon Peeples wrote:You are right Henry. I'll repost my original question. Thanks.


Thanks !!
 
GeeCON Prague 2014
 
subject: Removing substrings from strings