Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:API strfind
Jump to navigation
Jump to search
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!
{{luaapi}} string.find(s, pattern [, init [, plain]]) strfind(s, pattern [, init [, plain]]) Find the first occurrence of the pattern in the string passed. If an instance of the pattern is found a pair of values representing the start and end of the string is returned. If the pattern cannot be found nil is returned. > = string.find("Hello Lua user", "Lua") 7 9 > = string.find("Hello Lua user", "banana") nil We can optionally specify where to start the search with a third argument. The argument may also be negative which means we count back from the end of the string and start the search. > = string.find("Hello Lua user", "Lua", 1) -- start at first character 7 9 > = string.find("Hello Lua user", "Lua", 8) -- "Lua" not found again after character 8 nil > = string.find("Hello Lua user", "e", -5) -- first "e" 5 characters from the end 13 13 The pattern argument can be a regular expression which allows more complex searches. See the [http://lua-users.org/wiki/PatternsTutorial Patterns Tutorial on Lua-Users.org] and [[Pattern matching]] for more information. We can turn off the regular expression feature by using the optional fourth argument plain. plain takes a boolean value and must be preceded by init. E.g., > = string.find("Hello Lua user", "%su") -- find a space character followed by "u" 10 11 > = string.find("Hello Lua user", "%su", 1, true) -- turn on plain searches, now not found nil ==Example== Sometimes it's more appropriate to use string.find, rather than string.gmatch, eg: local msg = "Phase2:- There isn't any need for iterating over this mini-string."; local startPos, endPos, firstWord, restOfString = string.find( msg, "(%w+)[%s%p]*(.*)"); ==Result== startPos = 1 endPos = 66 firstWord = "Phase2" restOfString = "There isn't any need for iterating over this mini-string."
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Apinav
(
edit
)
Template:Editlink
(
edit
)
Template:Luaapi
(
edit
)
Template:Wowlua
(
edit
)