PtokaX and BCDC++ LUA scripts collection.
This site is powered by a CMS build in LUA! Made by plop.

HOME
pattern_matching
strsub
tables_and_arrays
email plop

Valid HTML 4.01!

strsub(string, start, [end])

strsub substracts a string from a string, from "start" to "end" (if end is not given it uses the end of the input string as end, -1)
in lua the first character in the string gets the value 1, if you want to count from the end of the string you have to use negative vallue's (-1 is the last character of the string).
so if you for example want to strip the first end last character of a string then strsub(string, 2, -2) does what you want.

start the next script with the command line lua.exe.
it gives a simple example of what strsub does.
when launched "start" and "end" are both 1, in the first loop "end" is increased by 1 every step.
the second increases "start" by 1 every step.
and as last it strippes the first and last character.

(strlen(string) returns the lenght of the given string.)

code:


text = "test string"
start = 1
End = 1

for i=1,strlen(text) do
string2 = strsub(text, start, End)
print(string2)
End = End +1
end

for i=1,strlen(text) do
string2 = strsub(text, start, End)
print(string2)
start = start + 1
end

print(strsub(text, 2, -2))




this is the result.
code:


t
te
tes
test
test
test s
test st
test str
test stri
test strin
test string
test string
est string
st string
t string
string
string
tring
ring
ing
ng
g
est strin




plop

ploppyrights reserved