RosettaCodeData/Task/Substring/XPL0/substring.xpl0

18 lines
606 B
Plaintext

include xpllib; \provides StrLen and StrFind
proc PMid(S, N, M); \Print string at Nth character M chars long
char S, N, M, I;
[for I:= 1 to M do ChOut(0, S(N-2+I));
CrLf(0);
];
char S;
def N=2, M=3;
[S:= "abcdefgh";
PMid(S, N, M); \starting from N chars in and of M length
PMid(S, N, StrLen(S)-N+1); \starting from N chars in, up to end of string
PMid(S, 1, StrLen(S)-1); \whole string minus last character
PMid(StrFind(S, "d" ), 1, M); \starting from known char and of M length
PMid(StrFind(S, "cd"), 1, M); \starting from known substring and of M length
]