获取 Blazor 中文本区域的换行符和回车符。
你可以使用 <br> 标签在 HTML 中插入换行符,这相当于键盘上的回车
Table of Contents
way 2.使用MarkupString
<br>
字符串替换新行,然后使用MarkupString
呈现为 HTML,但我会避免这种情况,因为这是不必要的安全风险 - 除非您将 HTML 存储在数据库中。
在字符串替换中使用正则表达式
@using System
@using System.Text.RegularExpressions
@using System.Web
EM.Body = (MarkupString)Regex.Replace(HttpUtility.HtmlEncode(EM.Body), @"\r\n?|\n", "<br />").Value;
https://www.soinside.com/question/ByKCY7e2kyAZFe3efKxhVE
https://www.soinside.com/question/5ozBFb4TDPHDj2uuVZPgbM
https://cloud.tencent.com/developer/ask/sof/108463918/answer/119443960