Module:String2/doc: Difference between revisions

Content deleted Content added
top: update for new calls
Functions: documentation for split function
Line 20:
=== ucfirst ===
The ucfirst function is similar to sentence; it renders the first alphabetical character in upper case, but leaves the capitalisation of the rest of the text unaltered. This is useful if the text contains proper nouns, but it will not regularise sentences that are ALLCAPS, for example. It also works with text containing piped wiki-links and with html lists. <s><code>label</code> is an alias to this function for backward compatibility.</s>(now obselete)
 
=== stripZeros ===
The stripZeros functions finds the first number in a string of text and strips leading zeros, but retains a zero which is followed by a decimal point. For example: "0940" -> "940"; "Year: 0023" -> "Year: 23"; "00.12" -> "0.12"
 
=== nowiki ===
The nowiki function ensures that a string of text is treated by the MediaWiki software as just a string, not code. It trims leading and trailing whitespace.
 
=== posnq ===
Line 32 ⟶ 26:
* It takes the text to be searched in as the first unnamed parameter, which is trimmed.
* It takes the text to match as the second unnamed parameter, which is trimmed and any double quotes " are stripped out. That allows spaces at the beginning or end of the match string to be included in a consistent manner.
 
=== split ===
The ''split'' function splits text at boundaries specified by separator and returns the chunk for the index idx (starting at 1). It can use positional parameters or named parameters (but these should not be mixed):
* <code><nowiki>{{#invoke:String2 |split |text |separator |index |true/false}}</nowiki></code>
* <code><nowiki>{{#invoke:String2 |split |txt=text |sep=separator |idx=index |plain=true/false}}</nowiki></code>
Any double quotes (") in the separator parameter are stripped out, which allows spaces and wikitext like <code><nowiki>["[</nowiki></code> to be passed. Use {{!}} for the pipe character <code>|</code>.
 
If the optional plain parameter is set to <code>false / no / 0</code> then separator is treated as a Lua pattern. The default is plain=true, i.e. normal text matching.
 
The index parameter is optional; it defaults to the first chunk of text.
 
=== stripZeros ===
The stripZeros functions finds the first number in a string of text and strips leading zeros, but retains a zero which is followed by a decimal point. For example: "0940" -> "940"; "Year: 0023" -> "Year: 23"; "00.12" -> "0.12"
 
=== nowiki ===
The nowiki function ensures that a string of text is treated by the MediaWiki software as just a string, not code. It trims leading and trailing whitespace.
 
== Usage ==