74 lines
1.3 KiB
Plaintext
74 lines
1.3 KiB
Plaintext
BYTE FUNC FindC(CHAR ARRAY text CHAR c)
|
|
BYTE i
|
|
|
|
i=1
|
|
WHILE i<=text(0)
|
|
DO
|
|
IF text(i)=c THEN
|
|
RETURN (i)
|
|
FI
|
|
i==+1
|
|
OD
|
|
RETURN (0)
|
|
|
|
BYTE FUNC FindS(CHAR ARRAY text,sub)
|
|
BYTE i,j,found
|
|
|
|
i=1
|
|
WHILE i<=text(0)-sub(0)+1
|
|
DO
|
|
found=0
|
|
FOR j=1 TO sub(0)
|
|
DO
|
|
IF text(i+j-1)#sub(j) THEN
|
|
found=0 EXIT
|
|
ELSE
|
|
found=1
|
|
FI
|
|
OD
|
|
IF found THEN
|
|
RETURN (i)
|
|
FI
|
|
i==+1
|
|
OD
|
|
RETURN (0)
|
|
|
|
PROC Main()
|
|
CHAR ARRAY text="qwertyuiop"
|
|
CHAR ARRAY sub="tyu"
|
|
CHAR ARRAY res(20)
|
|
BYTE n,m
|
|
CHAR c
|
|
|
|
PrintF("Original string:%E ""%S""%E%E",text)
|
|
|
|
n=3 m=5
|
|
SCopyS(res,text,n,n+m-1)
|
|
PrintF("Substring start from %B and length %B:%E ""%S""%E%E",n,m,res)
|
|
|
|
n=4
|
|
SCopyS(res,text,n,text(0))
|
|
PrintF("Substring start from %B up to the end:%E ""%S""%E%E",n,res)
|
|
|
|
SCopyS(res,text,1,text(0)-1)
|
|
PrintF("Whole string without the last char:%E ""%S""%E%E",res)
|
|
|
|
c='w m=4
|
|
n=FindC(text,c)
|
|
IF n=0 THEN
|
|
PrintF("Character '%C' not found in string%E%E",c)
|
|
ELSE
|
|
SCopyS(res,text,n,n+m-1)
|
|
PrintF("Substring start from '%C' and len %B:%E ""%S""%E%E",c,m,res)
|
|
FI
|
|
|
|
n=FindS(text,sub)
|
|
m=6
|
|
IF n=0 THEN
|
|
PrintF("String ""%S"" not found in string%E%E",sub)
|
|
ELSE
|
|
SCopyS(res,text,n,n+m-1)
|
|
PrintF("Substring start from '%S' and len %B: ""%S""%E%E",sub,m,res)
|
|
FI
|
|
RETURN
|