BYTE FUNC FindS(CHAR ARRAY text,sub BYTE start) BYTE i,j,found i=start 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) BYTE FUNC StartsWith(CHAR ARRAY text,sub) BYTE pos pos=FindS(text,sub,1) IF pos=1 THEN RETURN (1) FI RETURN (0) BYTE FUNC EndsWith(CHAR ARRAY text,sub) BYTE pos,start IF sub(0)>text(0) THEN RETURN (0) FI start=text(0)-sub(0)+1 pos=FindS(text,sub,start) IF pos=start THEN RETURN (1) FI RETURN (0) BYTE FUNC Contains(CHAR ARRAY text,sub BYTE ARRAY positions) BYTE pos,count pos=1 count=0 WHILE pos<=text(0) DO pos=FindS(text,sub,pos) IF pos>0 THEN positions(count)=pos count==+1 pos==+1 ELSE EXIT FI OD RETURN (count) PROC TestStartsWith(CHAR ARRAY text,sub) IF StartsWith(text,sub) THEN PrintF("""%S"" starts with ""%S"".%E",text,sub) ELSE PrintF("""%S"" does not start with ""%S"".%E",text,sub) FI RETURN PROC TestEndsWith(CHAR ARRAY text,sub) IF EndsWith(text,sub) THEN PrintF("""%S"" ends with ""%S"".%E",text,sub) ELSE PrintF("""%S"" does not end with ""%S"".%E",text,sub) FI RETURN PROC TestContains(CHAR ARRAY text,sub) BYTE ARRAY positions(20) BYTE i,count count=Contains(text,sub,positions) IF count>0 THEN PrintF("""%S"" contains %B ""%S"" at positions:",text,count,sub) FOR i=0 TO count-1 DO PrintB(positions(i)) IF i