#1 Convert <br> tags to new-lines or just spaces - and also the other way around
Requirements
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. |
#1 Convert <br> tags to new-lines or just spaces - and also the other way around
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 @using ToSic.Razor.Blade; <!-- unimportant stuff, hidden --> <div @Sys.PageParts.InfoWrapper()> @Html.Partial("../shared/DefaultInfoSection.cshtml") <div @Sys.PageParts.InfoIntro()> <h2><em>RazorBlade</em> Tags BR/NewLine Conversions <em>v1.1</em></h2> <p> These demos show how to convert BR tags to spaces, New-Lines or New-Lines to BRs. </p> </div> </div> <h2>Simple example</h2> @{ 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); } <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 --> @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })