RosettaCodeData/Task/Substring/Phix/substring-1.phix

30 lines
862 B
Plaintext

--(1) starting from n characters in and of m length;
--(2) starting from n characters in, up to the end of the string;
--(3) whole string minus last character;
--(4) starting from a known character within the string and of m length;
--(5) starting from a known substring within the string and of m length.
constant sentence = "the last thing the man said was the",
n = 10, m = 5
integer k, l
l = n+m-1
if l<=length(sentence) then
?sentence[n..l] -- (1)
end if
if n<=length(sentence) then
?sentence[n..-1] -- (2) or [n..$]
end if
if length(sentence)>0 then
?sentence[1..-2] -- (3) or [1..$-1]
end if
k = find('m',sentence)
l = k+m-1
if l<=length(sentence) then
?sentence[k..l] -- (4)
end if
k = match("aid",sentence)
l = k+m-1
if l<=length(sentence) then
?sentence[k..l] -- (5)
end if