Implements template {{Str find word}}.
| This module depends on the following other modules: |
Implements template {{Str find word}}.
This module looks for a word being present in a comma-separated list of words. It then returns a True or False value. By default, the True-value returned is the found word itself; the False-value is a blank string.
For example, in the source string 'foo, bar' the word 'bar' appears, but the word 'november' does not.
{{#invoke:Str find word |main |source=foo, bar |word=bar}} (True) → bar{{#invoke:Str find word |main |source=alpha, beta, gamma |word=november}} (False) →Multiple word check: The search can be extended to check for multiple words being present.
AND-list of words, all words must be present:
{{#invoke:Str find word |main |source=alpha, beta, gamma |andwords=beta, alpha}} (True) → beta,alpha{{#invoke:Str find word |main |source=alpha, beta, gamma |andwords=beta, omega}} (False) →OR-list of words, at least one off the words must be present:
{{#invoke:Str find word |main |source=alpha, beta, gamma |orwords=beta, alpha}} (True) → beta,alpha{{#invoke:Str find word |main |source=alpha, beta, gamma |orwords=beta, omega}} (False) → betaComplete words: the complete word is 'foobar' (example needed) Whitespace is trimmed,
The module is aimed at template code usage. (The editor does not have to apply Lua patterns like [%a%d]*).
}}
{{Str find word
|source= s=
|word= andwords= andw=
|orwords= orw=
|case=
|out-true=
|out-false=
}}
|
{{Str find word |s= |w= |andw= |orw= |case= |out-true= |out-false=}}
{{Str find word
|source =
|word =
}}
{{Str find word |source=cow, horse, dog, fish |word=dog}} (True) → dog{{Str find word |source=cow, horse, dog, fish |word=cat}} (False) →
|out-true= value (when entered non-empty).''), or the |out-false= value when entered.|source=alpha, foo, lima
|
|word=foo
|
foo | ||
|source=alpha, foo, lima
|
|word=bar
|
full word bar not in the source | ||
|source=alpha, foo, lima
|
|word=foobar
|
word foobar not in the source as full word |
|word= can be a list of words. All will be checked with the AND-requirement (each word must be present).|andwords= accepts a list of words that all will be checked with the AND-requirement (each word must be present).|word= and |andwords= are combined into one single AND-wordlist.|source=|s=
|
|andwords=|word=
|
result | note |
|---|---|---|---|
|s=alpha, foo, lima, delta
|
|andw=delta, lima
|
delta,lima | both words present in the source |
|s=alpha, foo, lima, delta
|
|andw=foo, nov
|
AND-logic: A word in the AND-list is not present (nov), so false | |
|s=alpha, foo, lima, delta
|
|andw=delta
|
delta | |w= and |andw= are combined
|
|s=alpha, foo, lima, delta
|
|andw=bar, april
|
delta |
|orwords=, |orw=|source=|s=
|
|orwords=
|
result | note | |
|---|---|---|---|---|
|s=alpha, foo, lima, delta
|
delta,lima | both words present in the source | ||
|s=alpha, foo, lima, delta
|
||||
|s=alpha, foo, lima, delta
|
|andw=delta
|
delta | |w= and |andw= are combined
| |
|s=alpha, foo, lima, delta
|
|orw=delta, lima
|
delta,lima | both OR-words are present in the source | |
|s=alpha, foo, lima, delta
|
foo | OR-logic: one of the words is present (|foo=), so true
| ||
|s=alpha, foo, lima, delta
|
|andw=alpha, lima
|
|orw=foo, nov
|
alpha,lima,foo | |
|s=alpha, foo, lima, delta
|
|andw=bar, april
|
|orw=nov, dec
|
none of the OR-words is present, so false |
|andwords= |orwords=|source=|s=
|
|andwords=|word=
|
|orwords=
|
result | note |
|---|---|---|---|---|
|s=alpha, foo, lima, delta
|
|andw=delta, lima
|
delta,lima | both words present in the source | |
|s=alpha, foo, lima, delta
|
|andw=foo, nov
|
AND-logic: A word in the AND-list is not present (nov), so false | ||
|s=alpha, foo, lima, delta
|
|andw=delta
|
delta | |w= and |andw= are combined
| |
|s=alpha, foo, lima, delta
|
|orw=delta, lima
|
delta,lima | both OR-words are present in the source | |
|s=alpha, foo, lima, delta
|
foo | OR-logic: one of the words is present (|foo=), so true
| ||
|s=alpha, foo, lima, delta
|
|andw=alpha, lima
|
|orw=foo, nov
|
alpha,lima,foo | |
|s=alpha, foo, lima, delta
|
|andw=bar, april
|
|orw=nov, dec
|
none of the OR-words is present, so false |
|source, andwords, orwords=<blank>
| ||||
|---|---|---|---|---|
|source=<blank>
|
|word=beta
|
|||
|source=alpha, beta, gamma
|
|word=<blank>
|
|||
|casesensitive=true, |case=true Case-sensitive (A=/=a) DEFAULT|casesensitive=false, |case=false Not case-sensitive (A=a)|source=|s=
|
|word=|w=
|
|case=
|
result | note |
|---|---|---|---|---|
|s=alpha, foo, lima
|
|w=foo
|
→ foo | ||
|s=alpha, foo, lima
|
|w=foobar
|
→ | ||
|s=alpha, foobar, lima
|
|w=foo
|
→ | 'foo' is not the complete word | |
|s=alpha, FOO, lima
|
|w=foo
|
→ foo | |case=false: a=A (default)
| |
|s=alpha, FOO, lima
|
|w=foo
|
→ | |case=true: a=/=A
|
|out-true=, out-false=|out-true=out-true, a hit|out-false=out-falset found
| ||||
|---|---|---|---|---|
|source=alpha, foo, lima
|
|word=foo
|
foo | ||
|source=alpha, foo, lima
|
|word=foobar
|
|||
|booleans=|booleans=true will convert all boolean words into "True/False".Yes, true, yes, 1 = true) (todo: document value 2?, nil, blanketc. Irrespective of case?)|booleans=true
| ||||
|---|---|---|---|---|
|source=YeS
|
|word=true
|
true | ||
|source=0
|
|word=FalSe
|
false | note: the word "false" is found and returned | |
|explain=true: when in Preview, display a report on input, output and the logical steps (debug).|explain=testcases: When set in ns Template or User on subpage /testcases, the Preview report is static (shown permanently).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.