我有包含列描述的表格电影。该列中的文本以以下格式保存:
This is movie about....
The best scene is...
当我想在GUI上的textarea中显示该文本时出现错误,因为它可以正确显示这种格式。当列中的格式如下所示时,它很有用:
This is movie about.... \n The best scene is...
然后它在textarea中正确显示它,一切都很好。 我试过这个:
bean.setDescription(movie.getDescription().replaceAll("\r\n", "\n"));
但它不起作用,它仍然将多行文本放到bean中。 有谁知道我怎么能将这个多行文本转换为单行文本并添加\ n?
答案 0 :(得分:0)
replaceAll
期望将正则表达式作为第一个输入,让我们尝试以下方法:
bean.setDescription(movie.getDescription().replaceAll("\\r|\\n", " "));