RosettaCodeData/Task/Substring/Lingo/substring.lingo

31 lines
706 B
Plaintext

str = "The quick brown fox jumps over the lazy dog"
-- starting from n characters in and of m length
n = 5
m = 11
put str.char[n..n+m-1]
-- "quick brown"
-- starting from n characters in, up to the end of the string
n = 11
put str.char[n..str.length]
-- "brown fox jumps over the lazy dog"
-- whole string minus last character
put str.char[1..str.length-1]
-- "The quick brown fox jumps over the lazy do"
-- starting from a known character within the string and of m length
c = "x"
m = 7
pos = offset(c, str)
put str.char[pos..pos+m-1]
-- "x jumps"
-- starting from a known substring within the string and of m length
sub = "fox"
m = 9
pos = offset(sub, str)
put str.char[pos..pos+m-1]
-- "fox jumps"