Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-11-2008, 11:29 AM
Moderator
 
Join Date: Nov 2007
Posts: 1,657
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Removing all the instances of a given text form a String
The method below can be used to remove all the occurrences of a given text from a String.
Code:
public static String removeJunk(String string, String strToRemove) { return string.replaceAll(strToRemove, " ").trim(); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-12-2008, 12:06 AM
Member
 
Join Date: Jan 2008
Posts: 24
afsina is on a distinguished road
incorrect.
Quote:
Originally Posted by Java Tip View Post
The method below can be used to remove all the occurrences of a given text from a String.
Code:
public static String removeJunk(String string, String strToRemove) { return string.replaceAll(strToRemove, " ").trim(); }
The given method replaces the given text with a space, and also it trims the given string, which is not the intended behavior in your description. API documentation should be very clear on what it does, Also, this method you gave is not null safe and is it pretty useless on what it does. if it would provide better naming, functionality and a clear documentation, it might be useful.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Naming object instances oldgit New To Java 9 02-08-2008 01:18 AM
image removing Triss New To Java 3 01-20-2008 10:27 PM
Removing characters kDude New To Java 3 12-03-2007 04:38 AM
Displaying text box on MIDlet form Java Tip Java Tips 0 11-22-2007 12:06 PM
removing an object from memory ravian New To Java 1 11-12-2007 11:23 PM


All times are GMT +3. The time now is 04:12 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org