我在下面的短信中插入换行符时遇到问题。目前我正在使用 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)
Run Code Online (Sandbox Code Playgroud)
我基本上想像这样展示它
You cannot split a sale
• With yourself.
• A representative that has not completed their IBA and not been approved by compliance.
• A terminated representative.
Run Code Online (Sandbox Code Playgroud)
编辑
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>
Run Code Online (Sandbox Code Playgroud)
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; }
Run Code Online (Sandbox Code Playgroud)
你需要改变
.Replace("@", Environment.NewLine)
Run Code Online (Sandbox Code Playgroud)
经过
.Replace("@", "<br />")
Run Code Online (Sandbox Code Playgroud)
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>"
Run Code Online (Sandbox Code Playgroud)
代码片段
.Replace("@", Environment.NewLine)
Run Code Online (Sandbox Code Playgroud)