Table of Contents

instr

in string - a string processing function that returns the character position of the first occurrence of a string in another string

syntax

instr(string1, string2 [, start])

details

The arguments string1 and string2 can be string variables, string functions or string literals.

The function returns an unsigned integer with one of the following values:

example

This example loops through a string in search of the term 'BASIC' and prints the start position each time the term was found.

' SharpBASIC instr programming example
' ------------------------------------
incl "lib/sys.sbi";

const text = "SharpBASIC is a great BASIC programming language";

dim n: uint;

main do
  ' initialize n and loop through the text
  loop n = 0 do
    ' look for the term 'BASIC'
    n = instr(text, "BASIC", n + 1);
    ' exit the loop if no more results
    if n == 0 do
      break;
    end
    ' print result
    print(n);
  end
end
Output:

6

23