HOW-TO: strsub
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

HOW-TO: strsub

Started by plop, 17 December, 2003, 02:36:47

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

plop

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.)
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.
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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

kepp

Hmm, i know i've seen this before, and i played with it :)

Thanks plop, That sure helped me :D
Guarding    

plop

QuoteOriginally posted by kepp
Hmm, i know i've seen this before, and i played with it :)

Thanks plop, That sure helped me :D
yep, posted it before on a question from you.
was a good example just i added some more.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

SMF spam blocked by CleanTalk