Removing carridge Return from A Java String


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Removing carridge Return from A Java String

  1. #1
    Join Date
    Apr 2005
    Posts
    12

    Removing carriage Return from A Java String

    I have a box with a string that i need to check to see if there is a carridge return in the box. If there is i need to remove it. Im fairly new to Java so im not really too good at it. Is there an example of this somewhere that i can learn from? Thanks.
    Last edited by bjr149; 06-12-2006 at 01:19 PM.

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    You could use the replace method of the String class, like:

    String cr2Blank=boxString.replace('\r',' ');

    Just remember, the replace methods create a new String, they don't change the initial String object.
    eschew obfuscation

  3. #3
    Join Date
    Jan 2007
    Posts
    60
    I am trying to do the same thing but it's not working

    Is there a way I can replace more than one character at a time?

    I want to replace the carriage return and hyphen so it splits and hyphenated word into 2.

    Code:
    while((textline = MyFile.readLine()) !=null)
           {
    	newString = textline.replace('\r',' ');
    	String[] numWords = newString.split(" ");
    
    	wordCount = wordCount + numWords.length;
    	System.out.println(textline);

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Nope, not to my knowledge. You have the replace and the replaceAll -methods for the String class. The last one will replace whole sequences of characters. However, to save keystrokes you could write:

    newString=textline.replace('\r',' ').replace('\'',' ');
    eschew obfuscation

Similar Threads

  1. SQL DMO Restores in VB?
    By ObiWan in forum VB Classic
    Replies: 3
    Last Post: 05-23-2006, 10:35 AM
  2. Getting a GUI to run
    By Eric in forum Java
    Replies: 4
    Last Post: 04-14-2006, 09:09 AM
  3. Re: App Object (fixes)
    By Rob Teixeira in forum .NET
    Replies: 129
    Last Post: 06-06-2002, 05:23 AM
  4. verify local admin
    By Patrick Comeau in forum VB Classic
    Replies: 6
    Last Post: 03-22-2001, 10:50 PM
  5. Please help me -- urgent -- deadlock error
    By chandra in forum VB Classic
    Replies: 0
    Last Post: 06-22-2000, 07:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center