Basically, all I'm trying to do is remove the newline character from a String in Java. I've looked at dozens of posts asking similar questions and they all say the same thing, but none of them seem to work for me. Here is all the code I have 3 lines:
String text = "\\n texttexttext \\n";
text = text.replaceAll("\\n", "");
System.out.println(text);
That string is similar to what I'm actually trying to use, but even with this one I can't find the newline character and replace it. The replaceAll just won't see it and I don't know why.
I've tried plenty of other things too like
text = text.replaceAll("\\n", "").replaceAll("\\r", "");
or
text = text.replaceAll("\\r\\n|\\r|\\n", " ");
but nothing can even find the character. I haven't even been able to find it using Regex Pattern and Matcher objects. The only thing slightly unusual I'm doing is doing it in a Junit Test bean, but I cannot believe that would do anything.
txtnot text - is that intended?String text = "\\n texttexttext \\n";, "\\n" here isn't a newline, it is literally a "\n".