Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Template:Str sub/doc: Difference between revisions

Template page
+ja
m format
 
(14 intermediate revisions by 11 users not shown)
Line 1: Line 1:
{{Documentation subpage}}
{{Lua|Module:String}}
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
{{TemplateBox
  |1        = 1
  |1label-en= text
  |1d-en    = The text to get the substring from.
  |1aliases = <!-- List of aliases, separated by / (a slash) -->
  |1type    = <!-- number, string, string/wiki-user-name, string/wiki-page-name, string/line; unknown -->
  |1def    = <!-- default value for the parameter -->
  |1stat    = required


=== Usage ===
  |2        = 2
  |2label-en= start
  |2d-en    = Zero-based index of the first character returned.
  |2aliases =  
  |2type    = number
  |2def    = 0
  |2stat    = optional


<nowiki>{{str_sub|</nowiki>''text''|''start''|''length''<nowiki>}}</nowiki> = Substring of ''text'' starting at ''start'' and containing ''length'' characters.
  |3        = 3
  |3label-en= length
  |3d-en    = The number of returned characters.
  |3aliases =
  |3type    = number
  |3def    = 0
  |3stat    = optional


''start'' + ''length'' must be less than 50. Only operates on a limited character set.
  |name              = Str sub long
 
  |desc              = This template returns the substring of <text> starting at <start> and containing <length> characters.<br>{{Nobold|Base 0: the first character is numbered 0, and so on, e.g. <nowiki>{{str sub long|20090624130510|8|2}}</nowiki> returns the 2 characters starting at the 9th, i.e. "{{str_sub|20090624130510|8|2}}".}}
 
  |usage-notes        =
=== See also ===
  |namespace          = template
 
  |usergroup          =  
<includeonly>
  |shorthand          =  
<!-- CATEGORIES AND INTERWIKIS HERE, THANKS -->
  |mustbesubst        =  
{{pp-template}}
  |setscats          =  
[[Category:String manipulation templates]]
  |placement          =  
 
  |example            =  
[[de:Vorlage:Strsub]]
  |example-value      =
[[ja:Template:Str sub]]
  |relieson          =
</includeonly>
  |seealso            = {{String templates see also}}
  |print              =
  |type              =
  |i18n-method        = -
  |i18n-desc          =
  |i18n-subpage      =
  |i18n-mediawiki-msg =
  |useTemplateData    = only
}}

Latest revision as of 16:38, 17 March 2022

This template returns the substring of <text> starting at <start> and containing <length> characters.
Base 0: the first character is numbered 0, and so on, e.g. {{str sub long|20090624130510|8|2}} returns the 2 characters starting at the 9th, i.e. "13".

Usage

{{Str sub long |1= |2= |3= }}

Template parameters

<templatedata>JSON</templatedata> ./. {{TemplateBox}}
TemplateData

TemplateData is a way to store information about template parameters (the description of those and of the whole template) for both humans and machines. It is used by VisualEditor and possibly other tools like Upload Wizard.


Existing template documentation
At Wikimedia Commons, it is recommended to use {{TemplateBox}} with either ‎useTemplateData=1 or ‎useTemplateData=only on the ‎/doc subpage and transcluding it with {{Documentation}} into the template. ‎<nowiki>-tags can be wrapped around the arguments, if required, to avoid templates being expanded.

Newly created template documentation and imports
Another option, especially for imported templates, or for users with JSON experience, is placing raw ‎<templatedata>-tags into the Wikitext of the template, as described in various Wikipediae.


Wikipedia's help about TemplateDataCommons-specific information

This template returns the substring of <text> starting at <start> and containing <length> characters.<br><span style="font-weight:normal">Base 0: the first character is numbered 0, and so on, e.g. {{str sub long|20090624130510|8|2}} returns the 2 characters starting at the 9th, i.e. "13".</span>

Template parameters

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
text1

The text to get the substring from.

Unknownrequired
start2

Zero-based index of the first character returned.

Default
0
Numberoptional
length3

The number of returned characters.

Default
0
Numberoptional

Additional information

The template is intended to be used in the following namespaces: the Template namespace

The template is intended to be used by the following user groups: no user group specified

See also

Trimming templates:

  • {{Trunc}} – To trim down to a specified number of characters.
  • {{Trim}} — To trim any leading or trailing whitespace.
  • {{Str left}} – To trim down to a specified number of characters, or duplicate the string to a specified number.
  • {{Str right}}
  • {{Strip}} – To strip (remove) a given number of characters from the beginning/end of the string

Analyzing templates:

  • {{Str endswith}} – To check if a string ends with a given string.
  • {{Str find}} – Returns the numerical location of a given string in a string, up to 50 characters.
  • {{Str len}} – Returns a string's length. Can count up to 500 characters.

String length comparison templates:

  • {{Str ≤ len}} – To check if a string is "shorter or equally long" or "longer" than a given length.

Sandboxes and test cases:

Technical stuff:

Localization

This template is not intended to be localized.

Cookies help us deliver our services. By using our services, you agree to our use of cookies.