GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||
GeezerVison is showing en.wikipedia.org — Help:Manipulating strings - Wikipedia
The English Wikipedia has several templates and Lua modules which can format or manipulate strings. In this context a string is any piece of text forming part of a page. This help page covers a few useful techniques; look in the navbox below for the full catalogue of templates. SubstringsThe simplest operation is taking a substring, a snippet of the string taken at a certain offset (called an "index") from the start or end. There are a number of legacy templates offering this (see navbox) but for new code use {{#invoke:String|sub|string|startIndex|endIndex}}. The indices are one-based (meaning the first is number one), inclusive (meaning the indices you specify are included), and may be negative to count from the other end. For example, Using existing templatesIf you think that someone will have done what you want before, look in the navbox below and check. It is much easier to find and use an existing template than to write complex code to do it all in one place. Look for a template that will do what you want all in one go. For example, rather than taking the final six characters of a string and checking if they are equal to "navbox", use {{str endswith|string|navbox}}. Automatically trimmed whitespaceIf you pass the string " If you use automatically numbered parameters ( Lua patterns (regex)Main article: mw:Extension:Scribunto/Lua reference manual § Patterns
Regular expressions (or regex) are a common and very versatile programming technique for manipulating strings. On Wikipedia you can use a limited version of regex called a Lua pattern to select and modify bits of text from a string. The pattern is a piece of code describing what you are looking for in the string. The symbols you an use in a pattern are:
Putting this all together, By wrapping part of the pattern in brackets, you can extract it, referencing it with the code
StringFunctions (from ParserFunctions)Wikipedia does not have the "StringFunctions" series of parser functions (listed below), and is not going to get them (per phab:T8455). Instead, templates use Lua (via Module:String or otherwise), alongside existing parser functions. None of these functions will work, but they have alternatives:
Testing codeIf you're not sure what some code is going to do, paste it into Special:ExpandTemplates, which will evaluate it for you to view. See alsoSee navbox chart below for various string-handling templates or parser functions. | |||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |