【发布时间】:2012-08-29 01:46:04
【问题描述】:
text = Daily 10 am - 5 pm.\\nClosed Thanksgiving and Christmas.
private String activateNewlines( String text ) {
String temp = text;
if ( text.contains( "\\n") ) {
while ( temp.contains( "\\n" ) ) {
int index = temp.indexOf( "\\n" );
temp = temp.substring( 0, index ) + temp.substring( index + 1 );
}
return temp;
}
return text;
}
我正在尝试为特殊字符删除额外的斜杠,但由于某种原因,子字符串最终会删除正斜杠。子字符串不喜欢字符串开头的斜线吗?最后的字符串变成了
Daily 10 am - 5 pm.nClosed Thanksgiving and Christmas.
我需要的是
Daily 10 am - 5 pm.\nClosed Thanksgiving and Christmas.
编辑:最终对我有用的东西:
String temp = text;
if ( text.contains( "\\n") ) {
temp = temp.replaceAll( "\\\\n", "\\\n" );
int x = 5;
return temp;
}
return text;
这实际上允许 TextView 识别换行符。
【问题讨论】: