Difference between revisions of "Template:Str len/doc"

From Ava Zinn Wiki
Jump to: navigation, search
[unchecked revision][unchecked revision]
(Starting out the documentation for this string length measuring template. Will add technical details later.)
 
m (46 revisions)
 
(45 intermediate revisions by 27 users not shown)
Line 1: Line 1:
{{documentation subpage}}
+
{{Documentation subpage}}
{{intricate template}}
+
{{Used in system}}
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
+
{{Lua|Module:String}}
 +
<!----PLEASE ADD CATEGORIES WHERE INDICATED AT THE BOTTOM OF THIS PAGE---->
 +
This is the {{tl|str len}} meta-template.
  
This is the {{tl|str len full}} meta-template.
+
It takes a string as parameter and returns its length (excluding spaces at the start and end). It can now count as high as necessary.
 
 
It takes a string as parameter and returns its length. It can count up to 500 in length, and returns 500 for strings that are too long.
 
 
 
'''Note!''' For most usage cases it is much easier and costs much less server resources to use {{tl|str ≥ len}} or one of its sister templates. See the [[#See also|see also]] section below.
 
 
 
=== Examples ===
 
  
 +
===Examples===
 
If the parameter is empty or undefined it is considered to be of zero length:  
 
If the parameter is empty or undefined it is considered to be of zero length:  
  
<pre>
+
:<code><nowiki>{{str len}}</nowiki></code> returns {{str len}}
{{str len full}}, {{str len full|}}, {{str len full| }}
+
:<code><nowiki>{{str len|}}</nowiki></code> returns {{str len|}}
</pre>
+
:<code><nowiki>{{str len| }}</nowiki></code> returns {{str len| }}
:{{str len full}}, {{str len full|}}, {{str len full| }}
 
 
 
This template counts the length of the string, even if it contains spaces or looks like a number:
 
 
 
<pre>
 
{{str len full| ab cde }}, {{str len full| 1234567 }}
 
</pre>
 
:{{str len full| ab cde }}, {{str len full| 1234567 }}
 
 
 
It can measure strings up to 500 in length, and returns 500 for strings that are too long:
 
 
 
<pre>
 
{{str len full| 499-characters... }}, {{str len full| 1000-characters... }}
 
</pre>
 
  
:{{str len full| abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi }}, {{str len full| abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghij }}
+
It counts the length correctly, even if the string contains spaces, looks like a number, or contains special characters:
  
=== Technical details ===
+
:<code><nowiki>{{str len| ab cde }}</nowiki></code> returns {{str len| ab cde }}
  
This template calls {{tl|str len full/core}} which does most of the work.
+
:<code><nowiki>{{str len| 1234567 }}</nowiki></code> returns {{str len| 1234567 }}
  
=== See also ===
+
:<code><nowiki>{{str len| café åäö }}</nowiki></code> returns {{str len| café åäö }}
  
Easy to use and efficient string length comparison templates:
+
:<code><nowiki>{{str len| 499-characters... }}</nowiki></code> returns {{str len| abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi }}
 +
:<code><nowiki>{{str len| 1000-characters... }}</nowiki></code> returns {{str len| abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghij }}
  
* {{tl|str ≥ len}} – To check if a string is "longer or equally long" vs. "shorter" than a given length.
+
===Template data===
* {{tl|str ≤ len}} – To check if a string is "shorter or equally long" vs. "longer" than a given length.
+
{{TemplateDataHeader}}
* {{tl|str ≠ len}} – To check if a string is "not equal" vs. "equal" to a given length.
+
<templatedata>
* {{tl|str ≤ ≥ len}} – To check all three of "shorter", "equal" and "longer" at the same time.
+
{
 +
        "description": "The template takes a string as parameter and returns its length, excluding spaces at the start and end of the string",
 +
        "params": {
 +
                "1": {
 +
                        "label": "Alpha-numeric text",
 +
                        "description": "The string to be counted",
 +
                        "type": "string",
 +
                        "required": true
 +
                }
 +
        }
 +
}
 +
</templatedata>
  
Much less efficient string length templates:
+
===Technical details===
 +
This is the first general-purpose template to be implemented using [[mw:Extension:Scribunto]]. The Lua code is located in [[Module:String]].
  
* {{tl|str len full}} – Can count up to 500 in length. Returns 500 for strings that are too long.
+
===See also===
* {{tl|strlen}} – Can only count up to 64 in length. Returns 64 for strings that are too long.
+
{{String-handling templates |IRL}}
* {{tl|str len}} – Can only count up to 80 in length. Returns an error message for strings longer than 80. And it counts any whitespace that surrounds its input.
 
  
 
<includeonly>
 
<includeonly>
<!-- CATEGORIES AND INTERWIKIS HERE, THANKS -->
+
{{#ifeq:{{SUBPAGENAME}}|sandbox | |
[[Category:String manipulation templates|{{PAGENAME}}]]
+
<!----CATEGORIES BELOW THIS LINE, PLEASE:---->
 
+
[[Category:String manipulation templates]]
 +
}}
 
</includeonly>
 
</includeonly>

Latest revision as of 08:33, 5 December 2016

Template:Used in system
Gnome-utilities-terminal.svg This template uses (or will be using) Lua programming language.

Please see Wikipedia:Lua if you want to learn more about Lua or help convert other templates.

This is the {{str len}} meta-template.

It takes a string as parameter and returns its length (excluding spaces at the start and end). It can now count as high as necessary.

Examples[edit]

If the parameter is empty or undefined it is considered to be of zero length:

{{str len}} returns 0
{{str len|}} returns 0
{{str len| }} returns 0

It counts the length correctly, even if the string contains spaces, looks like a number, or contains special characters:

{{str len| ab cde }} returns 6
{{str len| 1234567 }} returns 7
{{str len| café åäö }} returns 8
{{str len| 499-characters... }} returns 499
{{str len| 1000-characters... }} returns 500

Template data[edit]

This is the TemplateData documentation for this template used by VisualEditor and other tools.

Str len

The template takes a string as parameter and returns its length, excluding spaces at the start and end of the string

Template parameters

ParameterDescriptionTypeStatus
Alpha-numeric text1

The string to be counted

Default
empty
Example
empty
Auto value
empty
Stringrequired

Technical details[edit]

This is the first general-purpose template to be implemented using mw:Extension:Scribunto. The Lua code is located in Module:String.

See also[edit]