- 1). Load the NetBeans IDE by clicking on its program icon. When the program loads, navigate to "New/New Project" and select "Java Application" from the list on the right side of the screen. A new source code file appears in the NetBeans text editor. The source code file contains an empty main method.
- 2). Create a string and assign it some text. Be sure to add at least one carriage return character, which is specified by the character sequence "\r" in Java. You can write something like this between the curly brackets of the main method:
string strOriginal = "This is a string \rThis is a new line\r."; - 3). Replace the carriage return characters with spaces using the "replace" method. You can store the result of this method in a new string. Write the following to replace these characters:
string strNew = strOriginal.replace('\r', ' '); - 4). Print the value of "strNew" to the output window by writing the following:
System.out.println(strNew); - 5). Execute the program by pressing the F6 key. The program output looks like this:
This is a string This is a new line .
SHARE