c# - c#无法在字符串中插入换行符
问题描述
我在下面的短信中插入换行符时遇到问题。目前我正在使用 Environment.NewLine 但这似乎不起作用。这就是它的显示方式。
代码
error =
@"You cannot split a sale@
<ul>
<li>With yourself.</li>
<li>A representative that has not completed their IBA and not been approved by compliance.</li>
<li>A terminated representative.</li>
</ul>".Replace("@", Environment.NewLine)
我基本上想这样展示它
You cannot split a sale
• With yourself.
• A representative that has not completed their IBA and not been approved by compliance.
• A terminated representative.
编辑
html
<div class="row">
<div class="col-12 col-lg-6">
<div *ngIf="infoMessage" class="notification warning">
<fa-icon [icon]="['fas', 'info-circle']"></fa-icon>
<span [innerHTML]="infoMessage"></span>
</div>
</div>
</div>
CSS
.notification {
background: #d3d3d3;
border-radius: 7.5px;
margin: 0 0 15px;
padding: 7.5px 10px;
width: 100%;
span {
display: inline-flex;
margin: 0 0 0 10px;
}
}
.notification.success { background: $notification-success; color: $white; }
.notification.warning { background: $notification-warning; color: $white; }
.notification.error { background: $pink; color: $white; }
解决方案
你需要改变
.Replace("@", Environment.NewLine)
经过
.Replace("@", "<br />")
Environement.NewLine
是\r\n
这在 HTML 代码中毫无意义。
<br />
是 HTML 代码中的等价物。
为什么使用<br />
而不是\r\n
,因为您的错误字符串似乎在您显示它时被解释,看起来像在网站上。\r\n
在桌面应用程序中会很好。
编辑:或者您可以通过以下代码更新您的初始代码。
error =
@"You cannot split a sale
<p>
<ul>
<li>With yourself.</li>
<li>A representative that has not completed their IBA and not been approved by compliance.</li>
<li>A terminated representative.</li>
</ul></p>"
代码片段
You cannot split a sale
<p>
<ul>
<li>With yourself.</li>
<li>A representative that has not completed their IBA and not been approved by compliance.</li>
<li>A terminated representative.</li>
</ul>
</p>
<h4> Same With BR</h4>
You cannot split a sale
<br />
<ul>
<li>With yourself.</li>
<li>A representative that has not completed their IBA and not been approved by compliance.</li>
<li>A terminated representative.</li>
</ul>
推荐阅读
- wordpress - 如何使用第三方 Rest API 在 woocommerce 中添加自定义付款方式
- c - C中的链表从void函数返回一个指针
- node.js - 节点内存泄漏问题
- angular - ERROR TypeError: Cannot set property 'paginator' of undefined error is showing
- python - How to convert table to interaction list in python
- javascript - Is there a way to align dynamic cards horizontally using ajax?
- markdown - Markdown 标题包含 [ ] 之类的符号
- apache - 有没有显示 Litespeed 比 Nginx 服务器更快的基准?
- null - React-Admin 本地存储令牌空
- haskell - 可扩展的 GADT 是表达问题的可行解决方案吗?