Module talk:String2
When I try and use the One2a wrapper with convert on a faction such as {{one2a|{{convert|1/2|acre|spell=in}}}} it produces "a-half acre (0.20 ha)" with a hyphen, which isn't grammatically correct. Is there a way to change this to be a space? Thanks, --Voello talk 13:55, 15 January 2022 (UTC)
a half acre ({{convert|1/2|acre|disp=out}}) → a half acre (0.20 ha)This edit request has been answered. Set the |answered= parameter to no to reactivate your request. |
Currently ucfirst fails if you try to use it on for example 32nd or using html entites such as ×. Please update module with code from sandbox that fixes this. All ucfirst-testcases should be green afterwards. Tholme (talk) 15:31, 12 May 2022 (UTC)
If a page gets renamed, findpagetext no longer finds the text, and feels kinda lost. Can it be made to follow redirects (either using module:redirect or by itself)? — Guarapiranga ☎ 03:22, 7 June 2022 (UTC)
ucfirst()Re: this discussion (permalink) at Wikipedia:Help desk.
I have tweaked ucfirst() in Module:String2/sandbox to account for that case. I have tweaked Module:String2/testcases to show that I didn't break anything and to show that the ~/sandbox version correctly renders the string of wikilinks where the piped link is not the first link.
Comments desired. Without anyone comments, I shall update the live module from the sandbox.
—Trappist the monk (talk) 00:07, 25 February 2024 (UTC)
require ('strict'). I forget that other modules don't always use that. I've added it to this sandbox.mw.ustring.<whatever>() because unicode characters are allowed as article titles. I can imagine non-English redirect links for example.mw.ustring.sub() vs mw.ustring.gsub() but I have never really liked mw.ustring.sub() because to me, it is more cryptic than patterns. I don't suppose it really matters that much because I suspect that ucfirst() isn't used all that often.ucfirst() had specific code to handle <li> but no other tags. Why just that tag? So I've hacked ~/sandbox so that ucfirst() upcases the first letter character that is not in a stripmarker, an html-like tag, an html character or decimal/hexadecimal numeric entity, and strips the various list markup and miscellaneous punctuation. For example, non-English text wrapped in a {{lang}} template has multiple leading html tags:
{{lang|es|casa}} → <span title="Spanish-language text"><i lang="es">casa</i></span> → casa{{#invoke:String2/sandbox|ucfirst|{{lang|es|casa}}}} → Casa{{#invoke:String2|ucfirst|{{lang|es|casa}}}} → Casa{{#invoke:String2/sandbox|ucfirst|*house}}{{#invoke:String2/sandbox|ucfirst|*{{'}}house}} – {{'}} → <span class="nowrap" style="padding-left:0.1em;">'</span>{{#invoke:String2/sandbox|ucfirst|*''house''}}{{#invoke:String2/sandbox|ucfirst|*'''house'''}}{{#invoke:String2/sandbox|ucfirst|*''''house''''}} – malformed markup{{#invoke:String2/sandbox|ucfirst|*'''''house'''''}}I noticed that Module:String specifically does not have any dependencies, presumably so that it can be easily copied to other wikis. However, this module does, and the dependency it specifically requires is Module:GetParameters, which Module:String also uses: specifically, that module copies the function directly in its source to avoid any dependencies. (see: _str.getParameters)
I think it would be nice to do this also for this module, unless I'm misunderstanding the reasoning behind the original decision to omit it from Module:String. ClarFonThey (talk) 02:52, 5 July 2025 (UTC)
I created a wiki page that consisted of 10,000 invocations to trim a string, reloaded (purged) the page a couple of times and checked the CPU time usage in the generated HTML source code. Three different ways to trim 10,000 strings:
{{trim| foo }}: roughly between 0.5 seconds and 1.0 seconds{{#invoke|String2|trim| foo }}: between 2.5 seconds and 5.0 seconds{{#if:1| foo }}: between 0.1 seconds and 0.25 secondsI guess the bad performance of {{#invoke|String2|trim| foo }} is due to module loading. If you care about performance, you should probably use {{trim| foo }} instead. Or if you really care, use the {{#if:1| foo }} trick. — Chrisahn (talk) 10:00, 4 July 2026 (UTC)
This edit request has been answered. Set the |answered= parameter to no to reactivate your request. |
_getParameters() should not be exported, it should be local. I fixed it in the sandbox. See Special:Diff/1362498383. Please apply to the main template. Thanks! — Chrisahn (talk) 10:12, 4 July 2026 (UTC)Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.