Android:将字符串格式化为html - 添加新行< br /> [英] Android: Format string to html - add new lines <br/>

查看:383
本文介绍了Android:将字符串格式化为html - 添加新行< br />的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将来自用户的文本格式设置为HTML,但输入是多行文本,我必须将该字符串中的所有输入替换为HTML < br /> 标签。

  String message = messageEditText.getText()。toString(); 

这是我要格式化的讯息。

解决方案

try



<$ p $ (\\,< br>> );


I need to format text coming from user to HTML, but the input is multiple line and I have to replace all "enters" from that string to HTML <br /> tags.

String message = messageEditText.getText().toString();

This is the message I want to format. How can I format the string accordingly?

解决方案

try

message = message.replace ("\\r\\n", "<br>").replace ("\\n", "<br>");

这篇关于Android:将字符串格式化为html - 添加新行&lt; br /&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆