Skip to main content

Razor Blade Tutorials

Tutorial Home

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.

@{
  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);
}

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. Click to expand the code

@inherits Custom.Hybrid.Razor14
<!-- 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">
  <tr>
    <th class="w-25">This is...</th>
    <th class="w-33">Shown as plain text</th>
    <th class="w-33">Shown as HTML</th>
  </tr>
  <tr>
    <td>Original</td>
    <td><textarea rows="4">@val1</textarea></td>
    <td>@val1</td>
  </tr>
  <tr>
    <td>Converting with Tags.Nl2Br(...)</td>
    <td><textarea rows="4">@val1br</textarea></td>
    <td>@Html.Raw(val1br)</td>
  </tr>
  <tr>
    <td>Convert the br back with Tags.Br2Nl</td>
    <td><textarea rows="4">@val1Back</textarea></td>
    <td>@val1Back</td>
  </tr>
  <tr>
    <td>Cleaning BR as Space with Tags.Br2Space</td>
    <td><textarea rows="4">@val1Space</textarea></td>
    <td>@val1Space</td>
  </tr>

</table>



<!-- unimportant stuff, hidden -->