2.7. Chomping a String

Problem

You need to remove a trailing newline or carriage return from a string.

Solution

Use StringUtils.chomp( ) to remove the last line termination sequence from a string:

String input = "Hello
";
String chomped = StringUtils.chomp( input );
// chomped equals "Hello"

String input2 = "Another test
";
String chomped2 = StringUtils.chomp( input2 );
// chomped2 equals "Another test";
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.132.99