模块:String/doc
这是模块:String的文档页面
40px | 本-{zh-cn:模块; zh-tw:模組}-已应用于232,000+页面。 为避免大规模的破坏及不必要的服务器负荷,任何改动均应先在模板的沙盒、测试样例页面或您自己的用户页测试,经过测试後即可一次性改动本-{zh-cn:模块; zh-tw:模組}-。为尊重其他用户,任何改动在生效前都应先在讨论页讨论。 </td> </tr> </table> Module:string Lua错误:无法创建进程:proc_open不可用。请检查PHP的指令配置“disable_functions”。 This module is intended to provide access to basic string functions. Most of the functions provided here can be invoked with named parameters, unnamed parameters, or a mixture. If named parameters are used, Mediawiki will automatically remove any leading or trailing whitespace from the parameter. Depending on the intended use, it may be advantageous to either preserve or remove such whitespace. Global options
Unit tests for this module are available at Module:String/testcases. lenThis function returns the length of the target string. Usage:
OR
Parameters:
sub
Usage:
OR
Parameters:
The first character of the string is assigned an index of 1. If either i or j is a negative value, it is interpreted the same as selecting a character by counting from the end of the string. Hence, a value of -1 is the same as selecting the last character of the string. If the requested indices are out of range for the given string, an error is reported. sublengthThis function implements the features of {{Str sub old}} and is kept in order to maintain these older templates. matchThis function returns a substring from the source string that matches a specified pattern. Usage:
OR
Parameters:
If the match_number or start_index are out of range for the string being queried, then this function generates an error. An error is also generated if no match is found. If one adds the parameter ignore_errors=true, then the error will be suppressed and an empty string will be returned on any failure. For information on constructing Lua patterns, a form of regular expression, see:
posThis function returns a single character from the target string at position pos. Usage:
OR
Parameters:
The first character has an index value of 1. If one requests a negative value, this function will select a character by counting backwards from the end of the string. In other words pos = -1 is the same as asking for the last character. A requested value of zero, or a value greater than the length of the string returns an error. str_findThis function duplicates the behavior of {{str_find}}, including all of its quirks. This is provided in order to support existing templates, but is NOT RECOMMENDED for new code and templates. New code is recommended to use the "find" function instead. Returns the first index in "source" that is a match to "target". Indexing is 1-based, and the function returns -1 if the "target" string is not present in "source". Important Note: If the "target" string is empty / missing, this function returns a value of "1", which is generally unexpected behavior, and must be accounted for separatetly. findThis function allows one to search for a target string or pattern within another string. Usage:
OR
Parameters:
This function returns the first index >= "start" where "target" can be found within "source". Indices are 1-based. If "target" is not found, then this function returns 0. If either "source" or "target" are missing / empty, this function also returns 0. This function should be safe for UTF-8 strings. replaceThis function allows one to replace a target string or pattern within another string. Usage:
OR
Parameters:
repRepeats a string n times. A simple function to pipe string.rep to templates. Usage:
Parameters:
Example |