String matching: Difference between revisions

{{header|Liberty BASIC}}
(GP)
({{header|Liberty BASIC}})
Line 501:
loc = "abab".indexOf("ab",loc+1) //returns 2</lang>
 
=={{header|Liberty BASIC}}==
<lang lb>'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
</lang>
=={{header|Logo}}==
<lang logo>to starts.with? :sub :thing
Anonymous user