Android: Format string to html - add new lines <br/> [duplicate]
问题 This question already has answers here : replace \n and \r\n with <br /> in java (7 answers) Closed 5 years ago . 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? 回答1: try message = message.replace ("\\r\\n", "<br>").replace ("\\n", "<br>"); 回答2: You can use