Template:Str sub new

Template documentation[view · edit · history · purge]
This documentation is transcluded from Template:Str sub new/doc.
Category:Main message boxesCategory:Lua String-based templates

This template returns a substring of the input string, specified by the start and end parameters. It allows the usage of negative indices to conveniently specify lengths counting from the end of the string.

Usage


{{str sub new |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

Category:Templates using TemplateData

This template returns a substring of the input string, specified by the start and end parameters. It allows the usage of negative indices to conveniently specify lengths counting from the end of the string.

Template parameters

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
string1

The string to work with. Any leading and trailing whitespace is removed (the “length of the string” for other parameters refers to the length of the trimmed string).

Stringrequired
start2

The 1-based index of the first character of the string returned. If negative, it counts from the end of the string. Its absolute value must not be larger than the length of the input string.

Default
1
Linesuggested
end3

The 1-based index of the last character of the string returned. If negative, it counts from the end of the string. Its absolute value must not be larger than the length of the input string, and, after converted to a positive value, it must not be strictly smaller than the start index.

Default
-1
Linesuggested
no categorynocategory

If set to 'true' or 1, no category will be added if an error is generated.

Default
0
Booleanoptional

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: all users

Example

{{str sub new|1234567890|3|-3}}

renders as:

345678

Localization

This template is not intended to be localized.

Category:Templates not requiring internationalization

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:

Category:Lua String-based templates Category:Main message boxes Category:Templates not requiring internationalization Category:Templates using TemplateData