RosettaCodeData/Task/String-matching/Liberty-BASIC/string-matching.basic

31 lines
907 B
Plaintext

'1---Determining if the first string starts with second string
st1$="first string"
st2$="first"
if left$(st1$,len(st2$))=st2$ then
print "First string starts with second string."
end if
'2---Determining if the first string contains the second string at any location
'2.1---Print the location of the match for part 2
st1$="Mississippi"
st2$="i"
if instr(st1$,st2$) then
print "First string contains second string."
print "Second string is at location ";instr(st1$,st2$)
end if
'2.2---Handle multiple occurrences of a string for part 2.
pos=instr(st1$,st2$)
while pos
count=count+1
pos=instr(st1$,st2$,pos+len(st2$))
wend
print "Number of times second string appears in first string is ";count
'3---Determining if the first string ends with the second string
st1$="first string"
st2$="string"
if right$(st1$,len(st2$))=st2$ then
print "First string ends with second string."
end if