Results 1 to 2 of 2

Thread: In a listbox, how can you remove the end part of the entry after a string is found?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2002
    Posts
    628

    In a listbox, how can you remove the end part of the entry after a string is found?

    In my listbox, some items are being added with VbCrLf.. how can i loop through each listbox entry, search for the first instance of vbcrlf and remove the endpart of the string?

    for example - lets say | is a vbcrlf

    A very long string.lots. of formats_possible||||||Test
    A very long string.lots. of formats_possible|Test

    how can i remove the ||||||Test and the |Test??

  2. #2
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271
    Give this a try:
    Code:
    Private Sub Command1_Click()
      Dim i As Integer
      For i = 0 To List1.ListCount - 1
        If InStr(List1.List(i), vbCrLf) Then
          List1.List(i) = Left(List1.List(i), InStr(1, List1.List(i), vbCrLf) - 1)
        End If
      Next
    End Sub
    You could also strip the string before/while you add it to the list:
    Code:
    If InStr(StringToAdd, vbCrLf) Then
        List1.AddItem Left(StringToAdd, InStr(1, StringToAdd, vbCrLf) - 1)
      Else
        List1.AddItem StringToAdd
      End If
    Last edited by JohnVB6; Jun 20th, 2002 at 02:46 AM.
    Sometimes what you're looking for is exactly where you left it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width