string.gmatch

From GMod Wiki

(Redirected from String.gfind)
Jump to: navigation, search
Function
Syntax string.gmatch( String haystack, String needle, [ Function extra function ] )
Where is this used?
Description:
Returns an iterator function that, each time it is called, returns the next captures from pattern over string s. If pattern specifies no captures, then the whole match is produced in each call.
Returns: Function
Part of Library: String
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=String.gmatch]String.gmatch [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Example

DescriptionExample
Used onNewerShared.png
Code
 
     s = "hello world from Lua"
     for w in string.gmatch(s, "%a+") do
       print(w)
     end
Outputhello
world
from
Lua
DescriptionExample
Used onNewerShared.png
Code
 
     t = {}
     s = "from=world, to=Lua"
     for k, v in string.gmatch(s, "(%w+)=(%w+)") do
       t[k] = v
     end
OutputN/A


Additional notes

See also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox