lua-users home
lua-l archive

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


Hello,

I supposed that you mean `substring = string.sub( your_string, Start, End )`

We wil start with this:

    your_string = "Hi Andrew!"

Let's take the substring starting at the first character and ending at
the fourth one, and put it in the `hi_initial` variable.

    hi_initial = string.sub( your_string, 1, 4 ) --> Hi_initial is now "Hi A"

`your_string` has not been modified.
Now, we take the string that starts at the fourth letter and ending at
the second one starting from the end.

    name = string.sub( your_string, 4, -2 ) --> name is now "Andrew"

This is equivalent: start at the sixth from the end and end at the
ninth from the start.

    name = string.sub( your_string, -6, 9 ) --> name is now "Andrew"

I hope it helps.
-- Pierre-Yves



On Sat, Jan 21, 2012 at 18:41, Andrew <andrew12757@gmail.com> wrote:
> I'm only 11 and I'm a real newbie at lua. I'm having a little trouble with
> substring(), or saving my substring to a variable. Anyone know anything?
>