Forum

> > CS2D > Scripts > Weird strings
Forums overviewCS2D overview Scripts overviewLog in to reply

English Weird strings

4 replies
To the start Previous 1 Next To the start

old Weird strings

Deleted User

Quote
Hello guys. I need help in some problem.

Look at this function
1
2
3
4
5
6
7
8
function totable(t,match)
     local cmd = {}
     if not match then match = "[^%s]+" end
     for word in string.gmatch(t, match) do
          table.insert(cmd, word)
     end
     return cmd
end

the part:
1
match = "[^%s]+"

What the heck that string suppose to mean? Can you tell how do I call it, and where I can find tutorial about it?

old Re: Weird strings

DC
Admin Off Offline

Quote
It's a pattern matching with regular expressions.
http://lua-users.org/wiki/PatternsTutorial
http://www.wowpedia.org/Pattern_matching

Or just start a Google search for "Pattern Matching" or "Regular Expressions".

"[^%s]+"
means:
[ ] - defines a set of chars
^ - means not (so it matches all chars which are NOT in that set)
%s - all whitespaces
+ - one or more, will match as many as possible

"string.gmatch" iterates over a string and returns one matched char (or one matched substring?) per iteration.

With the pattern "[^%s]+" it will probably return all characters which are NO whitespaces or something like that.

old Re: Weird strings

EngiN33R
Moderator Off Offline

Quote
You could use %S+, too; capitalising a special symbol like %s provides its opposite.

old Re: Weird strings

omg
User Off Offline

Quote
if u google lua strings, it should come up

basically, ^%s and %S are the same things

in this case, it separates table components by whitespaces in the string

totable("lol lmao rofl")={lol,lmao,rofl}
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview