The StringBuffer class / base.StringBuffer methods |
Return the position of a substring.
getIndexOf( substr STRING, start INTEGER ) RETURNING result INTEGER
The getIndexOf() method returns the position of a substring in the string buffer. Specify the substring and an integer specifying the position at which the search should begin. Use 1 if you want to start at the beginning of the string buffer.
CALL buf.append("abcdef") DISPLAY buf.getIndexOf("def",1) -- Shows 4
MAIN DEFINE b base.StringBuffer DEFINE pos INTEGER DEFINE s STRING LET b = base.StringBuffer.create() CALL b.append("---abc-----abc--abc----") LET pos = 1 LET s = "abc" WHILE TRUE LET pos = b.getIndexOf(s,pos) IF pos == 0 THEN EXIT WHILE END IF DISPLAY "Pos: ", pos LET pos = pos + LENGTH(s) END WHILE END MAIN