Skip to main content

Razor Blade Tutorials

Tutorial HomeRazor.Blade

RazorBlade Tags.Strip(...) v1.1

These demos show how to strip all html from a string. You often need this in combination with crop or ellipsis to create teasers.

Simple example

Original

<h1>Introduction</h1><p>Welcome to this blog post</p><hr><p>beginning with xyz we'll tell you more</p>
which if cropped at 50 would be really messy
<h1>Introduction</h1><p>Welcome to this blog post<

After Strip

Introduction Welcome to this blog post beginning with xyz we'll tell you more

Usually you will then combine with crop or ellipsis

Introduction Welcome to this blog post beginning…

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
@using ToSic.Razor.Blade;
<!-- unimportant stuff, hidden -->
RazorBlade Tags.Strip(...) v1.1 These... <!-- unimportant stuff, hidden -->

@{
    var val1 = "<h1>Introduction</h1><p>Welcome to this blog post</p><hr><p>beginning with xyz we'll tell you more</p>";
    var cropLen = 50;
}

<h2>Simple example</h2>
<h3>Original</h3>
<code>@val1</code>

<div>which if cropped at @cropLen would be really messy</div>
<code>@val1.Substring(0, cropLen)</code>

<h3>After Strip</h3>
<code>@Tags.Strip(val1)</code>

<h3>Usually you will then combine with crop or ellipsis</h3>
<code>@Html.Raw(Text.Ellipsis(Tags.Strip(val1), cropLen))</code>

<!-- unimportant stuff, hidden -->