Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Str find word/doc
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
:TOC: [[#code]] ({{edit|Module:Str find word}}) {{Module:Str find word/links/doc}} {{Module rating|pre-alpha}} {{Lua|Module:Yesno|Module:TableTools|Module:String}} This module looks for a word being present in a comma-separated list of words. It then returns a {{code|True}} or {{code|False}} value. By default, the True-value returned is the found word itself; the False-value is a blank string. Implements {{tl|Str find word}}. For example, in the source string '{{mono|1=foo, bar}}' the word '{{mono|1=bar}}' appears, but the word '{{mono|1=november}}' does not. :True: <code><nowiki>{{#invoke:Str find word|main |source=foo, bar|word=bar}}</nowiki></code> → >{{#invoke:Str find word|main |source=foo, bar|word=bar}}< :False: <code><nowiki>{{#invoke:Str find word|main |source=alpha, beta, gamma|word=november}}</nowiki></code> → >{{#invoke:Str find word|main |source=alpha, beta, gamma|word=november}}< Complete words: the complete word is '{{mono|1=foobar}}' ... example needed ... ''Multiple word check'': The search can be extended to check for multiple words being present. ''AND''-list of words, all words must be present: :True: <code><nowiki>{{#invoke:Str find word|main |source=alpha, beta, gamma|andwords=beta, alpha}}</nowiki></code> → >{{#invoke:Str find word|main |source=alpha, beta, gamma|andwords=beta, alpha}}< :False: <code><nowiki>{{#invoke:Str find word|main |source=alpha, beta, gamma|andwords=beta, omega}}</nowiki></code> → >{{#invoke:Str find word|main |source=alpha, beta, gamma|andwords=beta, omega}}< ''OR''-list of words, at least one off the words must be present: :True: <code><nowiki>{{#invoke:Str find word|main |source=alpha, beta, gamma|orwords=beta, alpha}}</nowiki></code> → >{{#invoke:Str find word|main |source=alpha, beta, gamma|orwords=beta, alpha}}< :False: <code><nowiki>{{#invoke:Str find word|main |source=alpha, beta, gamma|orwords=beta, omega}}</nowiki></code> → >{{#invoke:Str find word|main |source=alpha, beta, gamma|orwords=beta, omega}}< The module is aimed at template code usage. <small>(The editor does not have to apply Lua patterns like {{code|1=[%a%d]*}})</small>. == Usage == :{{red|This documentation is not up to date}}. See template {{tl|Str find word}}. ==Parameters== :All parameters (synonyms) {| |- |<pre> {{Str find word |string = |word = |orwords = |case= |yes = |no = |explain = }} </pre> |<pre> {{Str find word |s = |w = |orw = |case= |yes = |no = |explain = }} </pre> |<pre> {{Str find word |s= source= |word= andwords= andw= |orwords= orw= |case= |yes= |no= |explain= <!-- |sep=todo --> }} </pre> |} <pre>{{Str find word |s= |w= |andw= |orw= |case= |yes= |no= |explain=}}</pre> ===Basic: source, word=== <pre> {{Str find word |source = |word = }} </pre> :When the ''word'' is found in the ''source'' (True), the function returns the ''word'' itself (by default), or {{para|yes}} value (when entered non-empty). :When not found (False), the function returns a empty string ({{code|''}}), or the {{para|no}} value when entered. {| class="wikitable" |- | {{para|1=source|2=alpha, foo, lima}} | {{para|word|foo}} | {{#invoke:Str find word|main |explain=true |source=alpha, foo, lima|word=foo}} | {{aye}} | |- | {{para|1=source|2=alpha, foo, lima}} | {{para|word|bar}} | {{#invoke:Str find word|main |explain=true |source=alpha, foo, lima|word=foo-bar}} | {{nay}} | full word ''bar'' not in the source |- | {{para|1=source|2=alpha, foo, lima}} | {{para|word|foobar}} | {{#invoke:Str find word|main |explain=true |source=alpha, foo, lima}} | {{nay}} | word ''foobar'' not in the source as full word |} ===Case, Literal, === : todo: examplify {| class="wikitable" style="" |- ! {{para|1=source}}<br/> {{para|1=s}} ! {{para|1=word}}<br/>{{para|1=w}} ! {{para|1=case}} ! result ! note |- | {{para|1=s|2=alpha, foo, lima}} | {{para|w|foo}} | | → {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima|w=foo|yes=yes|no=no}} | |- | {{para|1=s|2=alpha, foo, lima}} | {{para|w|foobar}} | | → {{#invoke:Str find word|main |explain=true |source=alpha, foo, lima|word=foobar|yes=yes|no=no}} | |- | {{para|1=s|2=alpha, foobar, lima}} | {{para|w|foo}} | | → {{#invoke:Str find word|main |explain=true |source=alpha, foobar, lima|word=foo|yes=yes|no=no}} | 'foo' is not the complete word |- | {{para|1=s|2=alpha, FOO, lima}} | {{para|w|foo}} | | → {{#invoke:Str find word|main |explain=true |source=alpha, FOO, lima|word=foo|yes=yes|no=no|case=false}} | {{para|case|false}}: a=A ''(default)'' |- | {{para|1=s|2=alpha, FOO, lima}} | {{para|w|foo}} | | → {{#invoke:Str find word|main |explain=true |source=alpha, FOO, lima|word=foo|yes=yes|no=no|case=true}} | {{para|case|true}}: a=/=A |} ===AND-, OR-wordlist checks=== :{{para|word}} as noted, can be a ''list of words''. All will be checked with the ''AND''-requirement (each word must be present). :{{para|andwords}} accepts a ''list of words'' that all will be checked with the ''AND''-requirement (each word must be present). ::When both {{para|word}}, {{para|andwords}} are present, they are combined into one single ''AND''-wordlist. :{{para|orwords}} accepts a ''list of words'' that all will be checked with the ''OR''-requirement (at least one of the words must be present). {| class="wikitable" style="" |- ! {{para|1=source}}<br/>{{para|1=s}} ! {{para|1=andwords}}, {{para|1=andw}}<br/>{{para|1=word}}<br/>{{para|1=w}} ! {{para|1=orwords}}<br/>{{para|1=orw}} ! result TODO fix ! note |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para|andw|delta, lima}} | | {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta|andw=delta, lima}} | both words present in the source |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para|andw|foo, nov}} | | {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta}} | AND-logic: A word in the ''AND''-list is not present ({{mono|nov}}), so false |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para|andw|delta}} | | {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta|andw=delta}} | {{para|w}} and {{para|andw}} are combined |- | {{para|1=s|2=alpha, foo, lima, delta}} | | {{para|orw|delta, lima}} | {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta|orw=delta, lima}} | both OR-words are present in the source |- | {{para|1=s|2=alpha, foo, lima, delta}} | | | {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta|orw=foo, nov}} | OR-logic: one of the words is present ({{para|foo}}), so true |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para|andw|alpha, lima}} | {{para|orw|foo, nov}} | {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta|andw=alpha, lima|orw=foo, nov}} | |- | {{para|1=s|2=alpha, foo, lima, delta}} | {{para|andw|bar, april}} | {{para|orw|nov, dec}} | {{#invoke:Str find word|main |explain=true |s=alpha, foo, lima, delta|andw=delta|orw=nov, dec}} | none of the OR-words is present, so false |} ===True, False rephrase options {{para|yes, no}}=== {| class="wikitable" |- ! colspan="5" style="padding-left:3em; text-align:left;" | {{code|1=...}} {{para|yes|Yes, hit}} {{para|no|Not found}} |- | {{para|1=source|2=alpha, foo, lima}} | {{para|word|foo}} | {{#invoke:Str find word|main |explain=true |source=alpha, foo, lima|word=foo|yes=Yes, hit|no=No, not found}} | {{aye}} |- | {{para|1=source|2=alpha, foo, lima}} | {{para|word|foobar}} | {{#invoke:Str find word|main |explain=true |source=alpha, foo, lima|word=foobar|yes=Yes, hit|no=No, not found}} | {{nay}} |} ===Edge cases: (blank input,) === :''todo'' ==issues and ideas== * Keep the order, Foo, bar -> foo(1), bar(2) ::eg table col userinput options, then cols in that order? * Check comma example above ({{code|1="Hello, world"}}) (currently returns: 2 hitwords & sep=comma Dec2022) *Make sure all boolean logic is by [[:Module:Yesno]] :''and'' resolve {{code|nil}} *option {{para|sep}} for output list >, < dflt ==Errors and analysis== * The logic itself does not produce errors. There is always a True of False result. * Pages with Unknown parameters are listed in {{clc|Category:Pages using str find word with unknown parameters}}. :There are no logical errors foreseen: any flaw in the input will return a False result (for example, no input strings to check were entered). * {{para|explain|true}}: when in {{button|Preview}}, display a report on input, output and the logical steps (debug). * {{para|explain|testcases}}: When set in ns {{mono|1=Template}} or {{mono|1=User}} on subpage {{mono|1=/testcases}}, the Preview report is static (shown permanently). ===code=== <includeonly>{{sandbox other|| [[:Category:Modules that manipulate strings]] }}</includeonly>
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Align
(
edit
)
Template:Aye
(
edit
)
Template:Button
(
edit
)
Template:Clc
(
edit
)
Template:Code
(
edit
)
Template:Dot
(
edit
)
Template:Edit
(
edit
)
Template:Lua
(
edit
)
Template:M links
(
edit
)
Template:Module rating
(
edit
)
Template:Mono
(
edit
)
Template:Nay
(
edit
)
Template:Para
(
edit
)
Template:Red
(
edit
)
Template:T links
(
edit
)
Template:Tl
(
edit
)
Template:Tla
(
edit
)
Module:Arguments
(
edit
)
Module:If preview
(
edit
)
Module:If preview/configuration
(
edit
)
Module:If preview/styles.css
(
edit
)
Module:Str find word
(
edit
)
Module:Str find word/links/doc
(
edit
)
Module:String
(
edit
)
Module:Yesno
(
edit
)