Skip to main content

Razor Blade Tutorials

Tutorial HomeRazor.Blade

RazorBlade Tags BR/NewLine Conversions v1.1

These demos show how to convert BR tags to spaces, New-Lines or New-Lines to BRs.

Simple example

This is... Shown as plain text Shown as HTML
Original This is a text. Second line. Third line.
Converting with Tags.Nl2Br(...) This is a text.
Second line.
Third line.
Convert the br back with Tags.Br2Nl This is a text. Second line. Third line.
Cleaning BR as Space with Tags.Br2Space This is a text. Second line. Third line.

Source Code of this file

Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials.

@inherits ToSic.Sxc.Dnn.RazorComponent
<!-- unimportant stuff, hidden -->
RazorBlade Tags BR/NewLine Conversions... <!-- unimportant stuff, hidden -->
@using ToSic.Razor.Blade;
    var val1 = "This is a text.\nSecond line.\nThird line.";
    var val1br = Tags.Nl2Br(val1);
    var val1Back = Tags.Br2Nl(val1br);
    var val1Space = Tags.Br2Space(val1br);

<h2>Simple example</h2>

<table class="table table-hover">
    <th class="w-25">This is...</th>
    <th class="w-33">Shown as plain text</th>
    <th class="w-33">Shown as HTML</th>
    <td><textarea rows="4">@val1</textarea></td>
    <td>Converting with Tags.Nl2Br(...)</td>
    <td><textarea rows="4">@val1br</textarea></td>
    <td>Convert the br back with Tags.Br2Nl</td>
    <td><textarea rows="4">@val1Back</textarea></td>
    <td>Cleaning BR as Space with Tags.Br2Space</td>
    <td><textarea rows="4">@val1Space</textarea></td>


<!-- unimportant stuff, hidden -->