Home All Groups Group Topic Archive Search About
Author
20 Mar 2006 9:01 PM
Brian Cahill
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.ReadLine()
         TextLine = TextLine.Substring(0, TextLine.LastIndexOf("/"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

Author
20 Mar 2006 9:05 PM
Nikolay Petrov
Do While objReader.Peek() <> -1
         TextLine = objReader.ReadLine()
         TextLine =
TextLine.Substring(TextLine.LastIndexOf("/"c),TextLine.lenght )
         MsgBox(TextLine)
Loop
Author
20 Mar 2006 9:25 PM
Brian Cahill
that gave me an error:

Index and length must refer to a location within the string.
Parameter name: length
Author
20 Mar 2006 9:29 PM
jvb
Try this

TextLine.Substring(0, TextLine.LastIndexOf("/"c))
Author
21 Mar 2006 4:14 PM
Claes Bergefall
TextLine = TextLine.Substring(TextLine.LastIndexOf("/"c))

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

   /claes

Show quoteHide quote
"Brian Cahill" <bcah***@wfs-ops.org> wrote in message
news:1142888469.480772.252660@z34g2000cwc.googlegroups.com...
>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.ReadLine()
>         TextLine = TextLine.Substring(0, TextLine.LastIndexOf("/"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
>