-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_text-crop-ellipsis.cshtml
More file actions
57 lines (50 loc) · 1.55 KB
/
_text-crop-ellipsis.cshtml
File metadata and controls
57 lines (50 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@using Connect.Razor.Blade;
<div>
return to <a href="@Link.To()">overview</a>
</div>
<h1 class="sc-element">
Razor Blade Text.Crop and Text.Ellipsis
@Edit.Toolbar(Content)
</h1>
<div>
These demos show how to crop text properly, because Razor Blade handles a lot of issues you'll usually have cropping text.
</div>
@{
// overlay numbers to show the real length
// 12345678901234567 890123 456 78901
var sample1 = "We love Tokyo, Zürich & München";
var realLength = 31;
}
<h2>Example Text</h2>
Original which visually has @realLength characters:
<ul>
<li>Unencoded: @sample1</li>
<li>As HTML: @Html.Raw(sample1)</li>
</ul>
<h2>Word-Split Problems</h2>
<div>
This demonstrates how strings are cut off in the middle of words if we don't use razor blade. It also breaks html entities like &amp; (the & character) or umlauts because ü = ü.
</div>
<table border="1">
<tr>
<th></th>
<th colspan="2"><em>C# Substring</em></th>
<th colspan="2"><em>Razor Blade</em></th>
</tr>
<tr>
<th>Length</th>
<th>C# Substring</th>
<th>C# dot-dot-dot</th>
<th>Text.Crop(...)</th>
<th>Text.Ellipsis(...)</th>
</tr>
@for(var len = 1; len <= 32; len++) {
<tr>
<td>@len</td>
<td>@sample1.Substring(0, len)</td>
<td>@sample1.Substring(0, len)...</td>
<td>@Html.Raw(Text.Crop(sample1, len))</td>
<td>@Html.Raw(Text.Ellipsis(sample1, len))</td>
</tr>
}
</table>