1

当获取数据库的字符串时:

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 和休息。

4

3 回答 3

2

有一个内置的行分隔符

 String newLine = System.getProperty("line.separator");
于 2013-08-07T13:45:19.337 回答
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");
  }
}

不能再复杂了,我挑战你:)

于 2013-08-07T14:02:52.590 回答
1

我觉得你可以试试

String finalInf = inf.replace("\\n", System.getProperty("line.separator"));
tV1.setText(finalInf);


System.getProperty("line.separator")) 

是新生产线的系统替代品

于 2013-08-07T13:45:11.047 回答