#4 RazorBlade - Text.Zip() lets you shrink all spaces, tabs, enters together
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
@inherits Custom.Hybrid.Razor14
<!-- unimportant stuff, hidden -->
@using ToSic.Razor.Blade;
@{
var samples = new string[] {
"This contains multi-spaces and \t\t\t tabs",
"This has \n \n line-breaks"
};
}
RazorBlade Text.Zip(...) v1.1 These... <!-- unimportant stuff, hidden -->
<h2>Correct and incorrect Character Counts</h2>
<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 -->