Fandom

WoWWiki

USERAPI GetWords

104,634pages on
this wiki
Add New Page
Talk4 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

This page documents a user-defined function that you can copy and paste into your addon. Replace <PREFIX> with your AddOn's prefix to avoid conflicts between different versions of these functions.
User defined functions < GetWords
GetWords - by Mikk -

Split a string on spaces (one or more) and return as a table.

wordList = <PREFIX>_GetWords("string with space separated words")


Function Parameters Edit

Arguments Edit

str 
String - containing words that you would like split

Returns Edit

wordList
Table - array of words in the string


Example Edit

wordList = <PREFIX>_GetWords("  string with   space   separated words");

ResultEdit

wordList[1]="string"
wordList[2]="with"
wordList[3]="space"
wordList[4]="separated"
wordList[5]="words"


CodeEdit

 function <PREFIX>_GetWords(str)
   local ret = {};
   local pos=0;
   while(true) do
     local word;
     _,pos,word=string.find(str, "^ *([^%s]+) *", pos+1);
     if(not word) then
       return ret;
     end
     table.insert(ret, word);
   end
 end

Also on Fandom

Random Wiki