-
Notifications
You must be signed in to change notification settings - Fork 0
/
_text-has.cshtml
86 lines (79 loc) · 2.19 KB
/
_text-has.cshtml
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
@using Connect.Razor.Blade;
<div>
return to <a href="@Link.To()">overview</a>
</div>
<h1 class="sc-element">
Razor Blade Text.Has
@Edit.Toolbar(Content)
</h1>
<div>
These demos show how to really check if a variable has text using Text.Has. This combines null-checks, empty checks, empty-html-nbsp-checks and more.
</div>
<h2>Examples</h2>
<table class="demo">
<tr>
<th>Test</th>
<th>Code</th>
<th>Result with html-ignore</th>
<th>...without html-ignore</th>
</tr>
<tr>
<td>Null value </td>
<td>Text.Has(null)</td>
<td>@Text.Has(null)</td>
<td>@Text.Has(null, false)</td>
</tr>
<tr>
<td>Just spaces </td>
<td>Text.Has(" ")</td>
<td>@Text.Has(" ")</td>
<td>@Text.Has(" ", false)</td>
<tr>
<td>text with only line breaks </td>
<td>Text.Has("\n\n")</td>
<td>@Text.Has("\n\n")</td>
<td>@Text.Has("\n\n", false)</td>
</tr>
<tr>
<td>text with tabs, whitespaces and line breaks </td>
<td>Text.Has("\n\t \n")</td>
<td>@Text.Has("\n\t \n")</td>
<td>@Text.Has("\n\t \n", false)</td>
</tr>
<tr>
<td>text with only nbsp characters </td>
<td>Text.Has("&nbsp; &nbsp;")</td>
<td>@Text.Has(" ")</td>
<td>@Text.Has(" ", false)</td>
</tr>
<tr>
<td>text with char-code of nbsp characters </td>
<td>Text.Has("#160;")</td>
<td>@Text.Has(" ")</td>
<td>@Text.Has(" ", false)</td>
</tr>
<tr>
<td>real text </td>
<td>Text.Has("real text")</td>
<td>@Text.Has("real text")</td>
<td>@Text.Has("real text", false)</td>
</tr>
<tr>
<td>Real text with nbps etc.</td>
<td>Text.Has("real\n text &nbsp;")</td>
<td>@Text.Has("real\n text ")</td>
<td>@Text.Has("real\n text ", false)</td>
</tr>
</table>
<h2>Special case: <BR> Whitespace</h2>
<ul>
<li>If your string is like Text.Has("<br>")</li>
<li>...then it will return: @Text.Has("<br>")</li>
<li>If you want to ignore BRs, combine it with <a href='@Link.To(parameters: "tags=true")'>Tags.Br2Nl(...)</a> </li>
<li>...resulting in: @Text.Has(Tags.Br2Nl("<br>"))</li>
</ul>
<style>
table.demo td {
white-space: pre-wrap;
}
</style>