#4 RazorBlade - Text.Zip() lets you shrink all spaces, tabs, enters together
Requirements
Resources
RazorBlade Text.Zip(...) v1.1
These demos show how to Zip (clean/compress) text properly, because Razor Blade handles a lot of issues you'll usually have cleaning up text. Scenarios might be:
- Multi-line text
- Cleane-up html, which may have more spaces and line-breaks than expected
- Just any text pasted from somewhere, which could even contain surprise white-space
Example Text
The example texts which have invisible problem characters:
-
This contains multi-spaces and ↦↦↦ tabs
-
This has ↵ ↵ line-breaks
Correct and incorrect Character Counts
Html output hides the problems | Whitespace output showing problems | Length | Output using Text.Zip(...) | Zip Length |
---|---|---|---|---|
This contains multi-spaces and tabs | This contains multi-spaces and tabs | 46 | This contains multi-spaces and tabs | 35 |
This has line-breaks | This has line-breaks | 25 | This has line-breaks | 20 |
#4 RazorBlade - Text.Zip() lets you shrink all spaces, tabs, enters together
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> Text.Zip(...) <em>v1.1</em></h2> <p> These demos show how to Zip (clean/compress) text properly, because Razor Blade handles a lot of issues you'll usually have cleaning up text. Scenarios might be: </p> <ul> <li>Multi-line text</li> <li>Cleane-up html, which may have more spaces and line-breaks than expected</li> <li>Just any text pasted from somewhere, which could even contain surprise white-space</li> </ul> </div> </div> <h2>Example Text</h2> <div> The example texts which have invisible problem characters: </div> <ol> @foreach (var s in samples) { <li> <code>@Html.Raw(ShowHiddenCharacters(s))</code> </li> } </ol> </trim> <h2>Correct and incorrect Character Counts</h2> @{ samples = new string[] { "This contains multi-spaces and \t\t\t tabs", "This has \n \n line-breaks" }; } <table class="table table-hover" width="100%"> <!-- table header --> <tr> <th>Html output hides the problems</th> <th class="table-warning">Whitespace output showing problems</th> <th>Length</th> <th class="table-success">Output using Text.Zip(...)</th> <th>Zip Length</th> </tr> <!-- the real code --> @foreach (var s in samples) { <tr> <td>@s </td> <td class="table-warning" style="white-space: pre-wrap;">@s</td> <td>@s.Length </td> <td class="table-success" style="white-space: pre-wrap;">@Text.Zip(s)</td> <td>@Text.Zip(s).Length</td> </tr> } </table> <!-- unimportant stuff, hidden --> @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })