2013-08-07 26 views
1

数据库的GetString时: n出现在字符串不是funcional

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

回答

1

我想你可以尝试

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


System.getProperty("line.separator")) 

是一个系统更换为新的生产线

+0

没有工作,我试过String finalInf = inf.replace(“\\\ n”,System.getProperty(“line.separator”));和字符串finalInf = inf.replace(“\ n”,System.getProperty(“line.separator”));但没有.. :( –

+0

您是否在android xml布局中设置了maxLine?(并使用\\ n) –

+0

最后我使用String finalInf = inf.replace(“\\ n”,System.getProperty(“line.separator “));并且工作正常,问题出在”\\\ n“和”\ n“不正确,正确的是”\\ n“ - >谢谢 –

2

有一个内置的行分隔符

String newLine = System.getProperty("line.separator"); 
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"); 
    } 
} 

不能更复杂,我挑战你:)

+0

这段代码有问题。 String [] inf2 = inf.split(“\”)中的错误; –

+0

已编辑,请立即尝试。 – g00dy