[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Accessing String contents
- From: Peng Zhicheng <pengzhicheng1986@...>
- Date: Fri, 22 Jun 2012 12:44:48 +0800
于 2012-6-21 11:44, Coda Highland 写道:
On Wed, Jun 20, 2012 at 10:43 PM, Coda Highland <firstname.lastname@example.org> wrote:
On Wed, Jun 20, 2012 at 10:36 PM, <email@example.com> wrote:
from a string in a table like this
I want to access/retrieve the n-th character.
Somewhere I read about, that in lua everything is a table,
therefore I thought that
would gives me "h" instead of an error.
But this may be thought too C-ish... ;)
I scanned through the String Tutorial, the String Library Tutotrial
and the online version of Programming Lua and found nothing what seems
appropiate to me...but I am sure that's due to me.... :)
What is the most cheapest (in terms of performance and programming
overhead) way to access the n-th character of a string which stored
at a certain index in a table?
Thank you very much in advance for any help!
Strings are tables, but the characters aren't table elements. Lua
doesn't offer that sugar. Instead, consult string.sub(). You'll
probably use it like this:
Correction: Strings are strings. Not everything in Lua is a table.
(Numbers aren't tables either, for example.) But strings have a common
metatable, which gives them access to the functions in the "string"
right, strings are strings.
in Lua, strings are not defined as arrays of characters(like C). strings are strings.
in fact, `string' is a built in type in Lua, while `character' or `char' is not.