lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tuesday 11 October 2005 21:29, Walter Cruz wrote:
[...]
> If i have a string like "Lua" :) in lua, how can I acess the "u"?

local substring = string.sub("Lua", 2, 2)

It's also possible to abuse string.byte() to do this, but that's only really 
useful in certain circumstances.

Speed tip:

local string_sub = string.sub
...lots of program here...
local substring = string_sub("Lua", 2, 2)

...is *substantially* faster than using string.sub directly.

Check out the string page in the manual:

http://www.lua.org/manual/5.0/manual.html#5.3

-- 
+- David Given --McQ-+ 
|  dg@cowlark.com    | "Never attribute to malice what can be adequately
| (dg@tao-group.com) | explained by stupidity." --- Nick Diamos
+- www.cowlark.com --+ 

Attachment: pgpYMMCkVf5e3.pgp
Description: PGP signature