none
LastIndexOf in SB RRS feed

Answers

  • I don't think there is a LastIndexOf command in SmallBasic, you could write a subroutine to do this though.  Here's an approach to get started.

    sample = "text to find text with more than one text"
    tofind = "text"

    pos = Text.GetIndexOf(sample,tofind)
    poslast = 0
    While (pos > 0)
      poslast = poslast+pos
      pos = Text.GetIndexOf(Text.GetSubTextToEnd(sample,poslast+1),tofind)
    EndWhile

    last = Text.GetSubText(sample,poslast,Text.GetLength(tofind))
    TextWindow.WriteLine("Last occurence of "+last+" is at position "+poslast)

    Wednesday, July 22, 2009 6:10 PM
    Moderator

All replies

  • I don't think there is a LastIndexOf command in SmallBasic, you could write a subroutine to do this though.  Here's an approach to get started.

    sample = "text to find text with more than one text"
    tofind = "text"

    pos = Text.GetIndexOf(sample,tofind)
    poslast = 0
    While (pos > 0)
      poslast = poslast+pos
      pos = Text.GetIndexOf(Text.GetSubTextToEnd(sample,poslast+1),tofind)
    EndWhile

    last = Text.GetSubText(sample,poslast,Text.GetLength(tofind))
    TextWindow.WriteLine("Last occurence of "+last+" is at position "+poslast)

    Wednesday, July 22, 2009 6:10 PM
    Moderator
  • Thanks.)
    Wednesday, July 22, 2009 7:28 PM