In the JTextArea, I want to separate the strings by '\n'. The sauce below is not working properly. I've already tried '\r\n | \r | n'.
public void insertUpdate(DocumentEvent e) {
String split[], docStr = null;
Document textAreaDoc = (Document)e.getDocument();
try {
docStr = textAreaDoc.getText(textAreaDoc.getStartPosition().getOffset(), textAreaDoc.getEndPosition().getOffset());
} } catch (BadLocationException e1) {
// // TODO Auto-generated catch block
e1.printStackTrace();
}
split = docStr.split("\\n");
}
String lines[] = String.split("\\r?\\n");
You can do it in this way.
© 2024 OneMinuteCode. All rights reserved.