The program:

!split out the next to last number of a Fibonacci series of length 9

LET fibn$="1,1,2,3,5,8,13,21,34"

PRINT "The series is ...";fibn$

! posr("target$","pattern$", position)

! target$ = fibn$

! pattern$ = ","

! position = posr(,,)

! find position of last comma

LET position = posr(fibn$,",",len(fibn$))

PRINT "Position of last comma is ... ";position

LET nlpos = posr(fibn$,",",posr(fibn$,",",len(fibn$))-1)

PRINT "Position of next-to-last comma is ...";nlpos

! now find the next to last value of the series

LET nextlast$ = fibn$[nlpos+1:position-1]

PRINT "The string value is ...";nextlast$ !check the string

LET nextlast = val(nextlast$) !convert string to number

PRINT "The next to last value of the series is ...";nextlast

END

 

The output:

The series is ...1,1,2,3,5,8,13,21,34

Position of last comma is ... 18

Position of next-to-last comma is ... 15

The string value is ...21

The next to last value of the series is ... 21