如何在JavaFX中从TextArea获取文本并保存换行符?

问题描述 投票:0回答:1

我有一个 TextArea 和其中的几行文本。当我通过 getText() 方法提取字符串时,我得到的是一行文本,而不是真正写的几行。那么如何区分 TextArea 中的每一行呢?

java javafx textarea
1个回答
0
投票

像这样使用.replaceAll

//replace the line breaks "\n" with System line separator...
//replace "yourTextAreaVariabe" with your own...
yourTextAreaVariable.getText().replaceAll("\n", System.getProperty("line.separator"));
© www.soinside.com 2019 - 2024. All rights reserved.