string formatting

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Cahill

    #1

    string formatting

    I am attempting to populate a listbox from a text file. I would like
    my result to get everything after that last "/" character. This code
    gets everything before.

    Do While objReader.Peek( ) <> -1
    TextLine = objReader.ReadL ine()
    TextLine = TextLine.Substr ing(0, TextLine.LastIn dexOf("/"c))
    MsgBox(TextLine )
    Loop

    Example:
    Applications/AS - ED Tracking Board/EDTB Train

    I would like it to result to this
    EDTB Train

    Instead I am getting this:
    Applications/AS - ED Tracking Board

    thanks

  • Nikolay Petrov

    #2
    Re: string formatting

    Do While objReader.Peek( ) <> -1
    TextLine = objReader.ReadL ine()
    TextLine =
    TextLine.Substr ing(TextLine.La stIndexOf("/"c),TextLine.le nght )
    MsgBox(TextLine )
    Loop

    Comment

    • Brian Cahill

      #3
      Re: string formatting

      that gave me an error:

      Index and length must refer to a location within the string.
      Parameter name: length

      Comment

      • jvb

        #4
        Re: string formatting

        Try this

        TextLine.Substr ing(0, TextLine.LastIn dexOf("/"c))

        Comment

        • Claes Bergefall

          #5
          Re: string formatting

          TextLine = TextLine.Substr ing(TextLine.La stIndexOf("/"c))

          Note that LastIndexOf returns -1 if it can't find the character (thus
          causing the above code to throw an exception)

          /claes

          "Brian Cahill" <bcahill@wfs-ops.org> wrote in message
          news:1142888469 .480772.252660@ z34g2000cwc.goo glegroups.com.. .[color=blue]
          >I am attempting to populate a listbox from a text file. I would like
          > my result to get everything after that last "/" character. This code
          > gets everything before.
          >
          > Do While objReader.Peek( ) <> -1
          > TextLine = objReader.ReadL ine()
          > TextLine = TextLine.Substr ing(0, TextLine.LastIn dexOf("/"c))
          > MsgBox(TextLine )
          > Loop
          >
          > Example:
          > Applications/AS - ED Tracking Board/EDTB Train
          >
          > I would like it to result to this
          > EDTB Train
          >
          > Instead I am getting this:
          > Applications/AS - ED Tracking Board
          >
          > thanks
          >[/color]


          Comment

          Working...