Modul:Hilfsfunktionen: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(Die Seite wurde neu angelegt: „ function robusttrim(s) if s==nil then return '' end local p=mw.ustring.gsub(s,'%[%[SMW::on%]%]','') p=mw.ustring.gsub(p,'%[%[SMW::off%]%]','') return…“) |
|||
Zeile 1: | Zeile 1: | ||
− | + | -- Macht einen Trim in Kombination mit dem Entfernen der SMW-Tags | |
− | + | function robusttrim(s) | |
− | + | if s==nil then return '' end | |
− | + | local p=mw.ustring.gsub(s,'%[%[SMW::on%]%]','') | |
− | + | p=mw.ustring.gsub(p,'%[%[SMW::off%]%]','') | |
− | + | return mw.text.trim(p) | |
− | + | end | |
− | + | ||
− | + | -- Splittet einen String in einen Array anhand eines Separators | |
− | + | function split(inputstr,sep) | |
− | + | if sep==nil then sep="%s" end | |
− | + | local t={} | |
− | + | local i=1 | |
− | + | for str in mw.ustring.gmatch(inputstr,"([^"..sep.."]+)") do | |
− | + | t[i]=str | |
− | + | i=i+1 | |
− | |||
end | end | ||
+ | if i==1 then t[1]=inputstr end | ||
+ | return t | ||
+ | end |
Version vom 18. Mai 2021, 16:45 Uhr
Dokumentation und Testfälle unter Modul:Hilfsfunktionen/Doku.
-- Macht einen Trim in Kombination mit dem Entfernen der SMW-Tags function robusttrim(s) if s==nil then return '' end local p=mw.ustring.gsub(s,'%[%[SMW::on%]%]','') p=mw.ustring.gsub(p,'%[%[SMW::off%]%]','') return mw.text.trim(p) end -- Splittet einen String in einen Array anhand eines Separators function split(inputstr,sep) if sep==nil then sep="%s" end local t={} local i=1 for str in mw.ustring.gmatch(inputstr,"([^"..sep.."]+)") do t[i]=str i=i+1 end if i==1 then t[1]=inputstr end return t end