RosettaCodeData/Task/String-matching/Run-BASIC/string-matching.run

29 lines
885 B
Plaintext

s1$ = "abc def ghi klmnop"
s2$ = "abc" ' begins with
s3$ = "ef" ' is in the string
s4$ = "nop" ' ends with
sn2$ = "abcx" ' not begins with
sn3$ = "efx" ' not in the string
sn4$ = "nopx" ' not ends with
if left$(s1$,len(s2$)) <> s2$ then a$ = "Not "
print "String:";s1$;" does ";a$;"begin with:";s2$
if instr(s1$,s3$) = 0 then a$ = "Not "
print "String:";s1$;" does ";a$;"contain:";s3$
if mid$(s1$,len(s1$) + 1 - len(s4$),len(s4$)) <> s4$ then a$ = "Not "
print "String:";s1$;" does ";a$;"end with:";s4$
' ----------- not -----------------------------
print
if left$(s1$,len(sn2$)) <> sn2$ then a$ = "Not "
print "String:";s1$;" does ";a$;"begin with:";sn2$
if instr(s1$,sn3$) = 0 then a$ = "Not "
print "String:";s1$;" does ";a$;"contain:";sn3$
if mid$(s1$,len(s1$) + 1 - len(sn4$),len(sn4$)) <> sn4$ then a$ = "Not "
print "String:";s1$;" does ";a$;"end with:";sn4$