This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Removing substrings from strings  RSS feed

 
Brandon Peeples
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brandon Peeples
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help Sebastian. I figured out where I made my error.
 
Henry Wong
author
Sheriff
Posts: 22831
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Brandon Peeples
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right Henry. I'll repost my original question. Thanks.
 
Henry Wong
author
Sheriff
Posts: 22831
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brandon Peeples wrote:You are right Henry. I'll repost my original question. Thanks.


Thanks !!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!