Results 1 to 2 of 2
  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    9

    Default 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.
    Java Code:
    	public static String removeJunk(String string, String strToRemove)
    	{	
    		return string.replaceAll(strToRemove, " ").trim();
    	}

  2. #2
    afsina is offline Member
    Join Date
    Jan 2008
    Posts
    24
    Rep Power
    0

    Default 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.
    Java 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.

Similar Threads

  1. Naming object instances
    By oldgit in forum New To Java
    Replies: 9
    Last Post: 02-07-2008, 11:18 PM
  2. image removing
    By Triss in forum New To Java
    Replies: 3
    Last Post: 01-20-2008, 08:27 PM
  3. Removing characters
    By kDude in forum New To Java
    Replies: 3
    Last Post: 12-03-2007, 02:38 AM
  4. Displaying text box on MIDlet form
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-22-2007, 10:06 AM
  5. removing an object from memory
    By ravian in forum New To Java
    Replies: 1
    Last Post: 11-12-2007, 09:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •