This module was considered for merging with Module:HTMLDecode on 2020 May 8. The result of the discussion was "no consensus". |
Text and/or other creative content from this version of Module:String was copied or moved into incubator:Module:Wp/nod/String with this edit. The former page's history now serves to provide attribution for that content in the latter page, and it must not be deleted as long as the latter page exists. |
This page has archives. Sections older than 90 days may be automatically archived by Lowercase sigmabot III when more than 5 sections are present. |
I am trying to extract a number from a string and ignore any units. I have been using {{ first word}} which works in some cases.
In the second case it doesn't work. I think because a nbsp is being used instead of a space. Is there any template which will work for both? — Martin ( MSGJ · talk) 08:20, 11 April 2022 (UTC)
18.6 nmi (34.4 km; 21.4 mi)
for the second case above. What is the purpose of this? If it's for convert and if you can control the parameters, using abbr=values would make selection easier. For the second case above, that would give 18.6 (34.4; 21.4)
.
Johnuniq (
talk) 11:01, 11 April 2022 (UTC)
Editors interested in this module may be interested in the following discussion: Template talk:Str rep#Pattern match irregularities. Your feedback would be welcome. Mathglot ( talk) 08:14, 8 October 2022 (UTC)
I am trying to use replace to strip out the level3 headers from a transclusion of Dublin North-West (Dáil constituency)#TDs.
However {{#invoke:String|replace|{{trim|{{#section-h:Dublin North-West (Dáil constituency)|TDs}}}}|%=%=%=[^%=]*%=%=%=||plain=false}}
leaves the level3 headers in place -- see my /sandbox test page at
special:permalink/1164910747
Any suggestions? Feel free to edit that sandbox if it helps. BrownHairedGirl (talk) • ( contribs) 21:13, 11 July 2023 (UTC)
{{#invoke:String|replace|{{trim|{{#section-h:Dublin North-West (Dáil constituency)|TDs}}}}|pattern=%=%=%=[^%=]*%=%=%=|replace=|plain=false}}
should work.
* Pppery *
it has begun... 22:09, 11 July 2023 (UTC)
This
edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
On Latin Wikipedia I have created a tiny module named
Module:Translitteratio, which contains a single function named abecedaria
. The function accepts three parameters and works exactly like the
translit
M4 macro (but with the order of arguments changed to chars, replacement, string). For example,
{{#invoke:translitteratio|abecedaria|aeiou|äëì|Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam mollis, metus ac volutpat auctor, sem ligula interdum nulla, ac pellentesque nibh erat sed nisi. Integer nec auctor orci. Quisque nibh metus, viverra et viverra nec, laoreet in mi. Integer aliquet, mauris vitae tristique fringilla, ante odio ultrices quam, et fermentum orci purus nec lorem. Integer quis vehicula arcu, et laoreet enim. Nulla euismod neque velit, eget iaculis massa tempor ut. Nulla convallis maximus neque et porttitor. In nunc eros, convallis id posuere ac, egestas et arcu. Aenean faucibus sollicitudin ipsum, in condimentum mauris maximus in. Etiam facilisis eros vel tortor tincidunt iaculis. Vestibulum lorem lectus, posuere sed enim in, varius pharetra lorem. Morbi nisl lacus, eleifend ut urna vitae, interdum consequat ipsum. Cras ut imperdiet ante. Sed quis luctus purus, quis porta erat. Ut gravida gravida augue a euismod.}}
generates
(You can experiment with it in the Latin Wikipedia sandbox page)
This allowed to write the {{ la:Sine notis diacriticis}} template, which transforms vowels with various accents into simple vowels, and the {{ la:Ufrac}} template, which writes fractions using only Unicode characters (no HTML).
I think that Module:String would benefit from this function, with its name changed from abecedaria
to translit
.
Translated into English, the code to add to this module would be:
str.translit = function( frame )
local args = frame.args
if args1 == nil or args1 == '' or args3 == nil or args3 == '' then
return ''
end
local npairs
local text = mw.text.split(args3], '', true)
local removenda = mw.text.split(args1], '', true)
local substituenda
if args2 ~= nil then
substituenda = mw.text.split(args2], '', true)
else
substituenda = {}
end
if #removenda > #substituenda then
npairs = #substituenda
else
npairs = #removenda
end
for idx1 = 1, npairs do
for idx2 = 1, #text do
if textidx2 == removendaidx1 then
textidx2 = substituendaidx1
end
end
end
for idx1 = npairs + 1, #removenda do
for idx2 = 1, #text do
if textidx2 == removendaidx1 then
table.remove(text, idx2)
end
end
end
return table.concat(text)
end
return str
Grufo ( talk) 17:40, 21 September 2023 (UTC)
translit
(this is just a clone). As for what can be done with it, I believe template {{
la:Ufrac}} has no languages. --
Grufo (
talk) 01:28, 22 September 2023 (UTC)
Why should we invent more ways to do the same thing?Because there are many cases where you have no alternatives. For instance, you can write,
100 {{Abbr|carats|A carat is ¹⁄₁₇₂₈ of a pound.}}
{{#invoke:translitteratio|abecedaria|0123456789|⁰¹²³⁴⁵⁶⁷⁸⁹|{{{1}}}}}
ĀĒĪŌŪȲĂĔĬŎŬÀÈÌÒÙỲÁÉÍÓÚÝÂÊÎÔÛŶāēīōūȳăĕĭŏŭàèìòùỳáéíóúýâêîôûŷ̄̆
This
edit request has been answered. Set the |answered= or |ans= parameter to no to reactivate your request. |
Please, add r to the word fist (resulting in first), line number 61. Nishimoto, Gilberto Kiyoshi ( talk) 18:11, 25 October 2023 (UTC)