Question

I'm trying to find the System.lineSeparator() in the getText() of a TextArea, in FX, but that's a bit unrelated. Anyway, I've got the following batch of code:

String newLine = System.lineSeparator();
String log = "Hello there!" + newLine + "I said hello!";
System.out.println(log);

The weird thing with the above, is that even though it outputs fine in the console, like so:

Hello there!
I said hello!

If I do System.out.println(log.indexOf(newLine);, I get -1 printed on the console, that means it didn't find it.

If I do System.out.println(log.indexOf("\n"); it returns 12, which is correct (as newLine is the 12th character in the log).

Anybody know what's up?

Was it helpful?

Solution

Posting above comment as an answer:

If I recall correctly, using Swing and JTextArea, .getText() converts all line separators to \n regardless of platform. I don't know if it works the same in TextArea in FX, but that might be a good place to start looking.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top