在使用此方法设置 TextView
的文本后,我似乎得到了一些额外的换行符
message.setText(Html.fromHtml( message ));
我怎样才能删除这些?它们导致我的布局变形,因为它向输出添加了两条额外的行。
字符串通过 Html.toHtml( editText.getText() ).trim();
保存到我的 sqlite 数据库中
初始字符串输入:hello
消息变量的日志输出:<p dir="ltr">hello</p>
最佳答案
你可以使用这条线......完全有效;)
我知道您的问题已解决,但也许有人觉得这很有用。
try{
string= replceLast(string,"<p dir=\"ltr\">", "");
string=replceLast(string,"</p>", "");
}catch (Exception e) {}
这里是 replaceLast ...
public String replceLast(String yourString, String frist,String second)
{
StringBuilder b = new StringBuilder(yourString);
b.replace(yourString.lastIndexOf(frist), yourString.lastIndexOf(frist)+frist.length(),second );
return b.toString();
}
关于android - 文本末尾的额外换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22418765/