当数据库的getstring时:
inf = c.getstring(5);
//inf is equals "Hello how are you?\nFine and you\nI am fine, thanks.";
当我打印时,它以相同的方式显示,并且不执行参数“\ n”:
tV1.setText(inf);
//the text "is Hello how are you?\nFine and you\nI am fine, thanks."
但我想:
"Hello how are you?
Fine and you
I am fine, thanks."
有什么问题?
我的解决方案:
String finalInf = inf.replace("\\n", System.getProperty("line.separator"));
tV1.setText(finalInf);
谢谢:Skaard-Solo和休息。
答案 0 :(得分:2)
有一个内置行分隔符
String newLine = System.getProperty("line.separator");
答案 1 :(得分:2)
使用它:
String inf = c.getstring(5);
String [] inf2 = inf.split("\\").
for (int i = 0; i < inf2.length(); i++){
if(i < inf2.length() -1){
inf += inf2[i].substring(1,inf2[2].length()) + System.getProperty("line.separator");
}
}
不能更复杂,我挑战你:)
答案 2 :(得分:1)
我想你可以试试
String finalInf = inf.replace("\\n", System.getProperty("line.separator"));
tV1.setText(finalInf);
System.getProperty("line.separator"))
是新行的系统替换