Following code snippet shows how to remove line termination characters from a String.
import java.util.regex.*;
public class ClassA {
public static void main(String args []) {
String inputText = "sdfsdfsf\nsdfsdfsd";
String inputText2 = "var trpListenerGr\naphDivId = #trpLi\nstenerGraph2\n";
RemoveLineTerminationCharacterss(inputText);
System.out.println("-------------------------------");
RemoveLineTerminationCharacterss(inputText2);
}
public static String RemoveLineTerminationCharacterss(String inputText){
Pattern p;
Matcher m;
System.out.println(" Input Text : " + inputText);
p = Pattern.compile("\n");
m = p.matcher(inputText);
String str = m.replaceAll("");
System.out.println(" OUtput Text: " + str);
return str;
}
}
3 comments:
Good post, it helped me solve a problem I've been working on for a little while. Thanks!
Thanks a lot . It worked.
I'm Glad that you found it helpful.
Thanks,
Heshan.
Post a Comment