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 02:19 PM.
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.
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.
while((textline = MyFile.readLine()) !=null)
newString = textline.replace('\r',' ');
String numWords = newString.split(" ");
wordCount = wordCount + numWords.length;
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('\'',' ');
By ObiWan in forum VB Classic
Last Post: 05-23-2006, 11:35 AM
Last Post: 04-14-2006, 10:09 AM
By Rob Teixeira in forum .NET
Last Post: 06-06-2002, 06:23 AM
By Patrick Comeau in forum VB Classic
Last Post: 03-22-2001, 11:50 PM
By chandra in forum VB Classic
Last Post: 06-22-2000, 08:36 AM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center