Requirements
Resources
RazorBlade Text.First(...) v3
These demos show how to get the first real text of a series of values. Basically it will ignore nulls, empty texts, space-strings and even combinations containing empty lines, html-nbsps and more. Internally it uses Text.Has(...).
Initial Code
The following code runs at the beginning and creates some variables/services used in the following samples.
Demos
Basic 2-Value Demos
-
Text.First(null, John)
⇒ John -
Text.First(null, null)
⇒ -
Text.First(John, Michael)
⇒ John -
Text.First(" " = 3 spaces, John)
⇒ John -
Text.First(null, please-enter-name)
⇒ please-enter-name -
Text.First( , please-enter-name)
⇒ please-enter-name -
Text.First(false, , please-enter-name)
⇒
"false" at the end means don't treat html-whitespace as whitespace, so will be treated as a real value
3-5 Value Demos
Text.First has overloads (multiple signatures) for up to 5 values, and another one accepting an array of string objects so you can even use it for 10 values if you really need it.
-
Text.First(null, John, please-enter-name)
⇒ John -
Text.First(null, John, Michael, please-enter-name)
⇒ John -
Text.First(null, , John, Michael, please-enter-name)
⇒ John -
Text.First(false, null, , John, Michael, please-enter-name)
⇒ -
Text.First(null, null, , John, Michael, " ", please-enter-name)
⇒ John -
Text.First(false, null, null, , John, Michael, " ", please-enter-name)
⇒
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.First(...) <em>v3</em></h2> <p> These demos show how to get the first <em>real</em> text of a series of values. Basically it will ignore nulls, empty texts, space-strings and even combinations containing empty lines, html-nbsps and more. Internally it uses @Sys.TutLink("Text.Has(...)", "blade120/page"). </p> </div> </div> @{ var val1 = "John"; var val2 = "Michael"; var spc = " "; var fallback = "please-enter-name"; var nbsp = " "; } Demos Basic 2-Value Demos <ol> <li> <code>Text.First(null, @val1)</code> ⇒ @Text.First(null, val1) </li> <li> <code>Text.First(null, null)</code> ⇒ @Text.First(null, null) </li> <li> <code>Text.First(@val1, @val2)</code> ⇒ @Text.First(val1, val2) </li> <li> <code>Text.First("@spc" = 3 spaces, @val1)</code> ⇒ @Text.First(spc, val1) </li> <li> <code>Text.First(null, @fallback)</code> ⇒ @Text.First(null, fallback) </li> <li> <code>Text.First(@nbsp, @fallback)</code> ⇒ @Text.First(nbsp, fallback) </li> <li> <code>Text.First(false, @nbsp, @fallback)</code> ⇒ @Text.First(false, nbsp, fallback) <br> <em></em>"false" at the end means don't treat html-whitespace as whitespace, so @nbsp will be treated as a real value</em> </li> </ol> 3-5 Value Demos Text.First has overloads... <!-- unimportant stuff, hidden --> <ol> <li> <code>Text.First(null, @val1, @fallback)</code> ⇒ @Text.First(null, val1, fallback) </li> <li> <code>Text.First(null, @val1, @val2, @fallback)</code> ⇒ @Text.First(null, val1, val2, fallback) </li> <li> <code>Text.First(null, @nbsp, @val1, @val2, @fallback)</code> ⇒ @Text.First(null, nbsp, val1, val2, fallback) </li> <li> <code>Text.First(false, null, @nbsp, @val1, @val2, @fallback)</code> ⇒ @Text.First(false, null, nbsp, val1, val2, fallback) </li> <li> <code>Text.First(null, null, @nbsp, @val1, @val2, "@spc", @fallback)</code> ⇒ @Text.First(null, null, nbsp, val1, val2, spc, fallback) </li> <li> <code>Text.First(false, null, null, @nbsp, @val1, @val2, "@spc", @fallback)</code> ⇒ @Text.First(false, null, null, nbsp, val1, val2, spc, fallback) </li> </ol> @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })