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:String/doc
(section)
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!
== find == This function allows one to search for a target string or pattern within another string. Usage: : <code><nowiki>{{#invoke:</nowiki>String|find|''source_string''|''target_string''|''start_index''|''plain_flag''}}</code> OR : <code><nowiki>{{#invoke:</nowiki>String|find|source= ''source_string'' |target= ''target_string'' |start= ''start_index'' |plain= ''plain_flag'' }}</code> Parameters: ; source : The string to search ; target : The string or pattern to find within source ; start : The index within the source string to start the search, defaults to 1 ; plain : Boolean flag indicating that target should be understood as plain text and not as a [[mw:Extension:Scribunto/Lua reference manual#Ustring patterns|Scribunto ustring pattern]] (a unicode-friendly [[w:en:Lua (programming language)|Lua]]-style [[w:en:regular expression|regular expression]]); defaults to true This function returns the first index >= "start" where "target" can be found within "source". Indices are 1-based. If "target" is not found, then this function returns 0. If either "source" or "target" are missing / empty, this function also returns 0. This function should be safe for UTF-8 strings. Examples: * <code><nowiki>{{#invoke:String|find|abc123def|12}}</nowiki></code> β {{#invoke:String|find|abc123def|12}} * <code><nowiki>{{#invoke:String|find|source=abc123def|target=12}}</nowiki></code> β {{#invoke:String|find|source=abc123def|target=12}} * <code><nowiki>{{#invoke:String|find|source=abc123def|target=pqr}}</nowiki></code> β {{#invoke:String|find|source=abc123def|target=pqr}} * <code><nowiki>{{#invoke:String|find| abc123def |123}}</nowiki></code> β {{#invoke:String|find| abc123def |123}} * <code><nowiki>{{#invoke:String|find|source= abc123def |target= 123 }}</nowiki></code> β {{#invoke:String|find|source= abc123def |target= 123 }} * <code><nowiki>{{#invoke:String|find|source=abc123def|target=%d |start=3 |plain=false }}</nowiki></code> β {{#invoke:String|find|source=abc123def|target=%d |start=3 |plain=false }} When using unnamed parameters, preceding and trailing spaces are kept and counted: * <code><nowiki>{{#invoke:String|find| abc123def |c|false}}</nowiki></code> β {{#invoke:String|find| abc123def |c|false}} * <code><nowiki>{{#invoke:String|find|source= abc123def |target=c|plain=false}}</nowiki></code> β {{#invoke:String|find|source= abc123def |target=c|plain=false}} * <code><nowiki>{{#invoke:string|find|abc 123 def|%s|plain=false}}</nowiki></code> β {{#invoke:string|find|abc 123 def|%s|plain=false}} Testing for the presence of a string: * <code>{{pf|ifexpr|<nowiki>{{#invoke:string|find|haystack|needle}}</nowiki>|Found needle|Didn't find needle}}</code> β {{#ifexpr:{{#invoke:string|find|haystack|needle}}|Found needle|Didn't find needle}} {{anchor|replace}}
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)