INSTR

SmallBASIC syntax groups: 


String function INSTR


10
20  INSTR ([start,] s1, s2)
30
Returns the position of the first occurrence of the string s2 into string s1 (starting from the position ‘start’). If there is no match, INSTR returns 0


See examples


If there is insufficient information on this page and you wish learn more about INSTR, please send an email to smallbasic@gmail.com. You can help to improve information about INSTR by submitting an article using the comments link below. Note, an offline language reference text file is now avialable – see the Download section.

Comments

' INSTR oddity.bas  SmallBASIC 0.12.2 [B+=MGA] 2016-03-08
'this oddity was discovered with inkey failure to work as expected

?instr("ABCD","")    'aha! returns 1
pause
'end

'I am trying to figure out why the following code wont work, it's because instr("anything","")=1
while 1
s=" x=exit n=nice r=random g=globe"
at (xmax-txtw(s))\2,0:?s
repeat
  ink=inkey
  ink=upper(ink)
  delay 20
'until ink="X" or ink="Q" or ink="N" or ink="R" or ink="G" '<= this works great!
until instr("XQNRG",ink)>0 '<==== this refuses to work right
cls
at 0,3*txth("Q"):? "You pressed '";ink;"'"
? " instr XQNRG,ink  '";instr("XQNRG",ink);"'  press any..."
pause
if ink="X" then ? "Goodbye":end
wend