0

以下代码有效,只需将每一行作为列表框中的一行。

Reader = IO.File.OpenText(textlocation)
Dim bookmarks() As String = Reader.ReadToEnd.Split(vbNewLine)
Dim i As Integer = 0

Do Until i = bookmarks.Length
  lstFavorites.Items.Add(bookmarks(i))
  i += 1
Loop

但我不希望每一行都进入文本框。我只希望包含文本“书签”的行进入列表框。我能做些什么来实现这一目标?我已经尝试了我能想到的一切。

这是我尝试过的一些代码,我看不到其中的问题,但它似乎只是让我的程序崩溃。

Do Until i = bookmarks.Length
  If bookmarks(i).Contains("at") Then
    If radBookmarks.Checked Then
      If bookmarks(i).Contains("Bookmark") Then
        Original = bookmarks(i)
        BeginningOfDemoName = Original.Substring(Original.LastIndexOf("(") + 2)
        TickWithParenthesis = BeginningOfDemoName.Substring(BeginningOfDemoName.IndexOf(Chr(34)) + 4)
        Tick = TickWithParenthesis.Split(" ")(1).Split(")")(0)
        DemoName = BeginningOfDemoName.Split(Chr(34))(0)
        ToList = DemoName + " at " + Tick
        lstFavorites.Items.Add(ToList)
        i += 1
      Else
        i += 1
      End If
    ElseIf radEverything.Checked Then
      Original = bookmarks(i)
      BeginningOfDemoName = Original.Substring(Original.LastIndexOf("(") + 2)
      TickWithParenthesis = BeginningOfDemoName.Substring(BeginningOfDemoName.IndexOf(Chr(34)) + 4)
      Tick = TickWithParenthesis.Split(" ")(1).Split(")")(0)
      DemoName = BeginningOfDemoName.Split(Chr(34))(0)
      ToList = DemoName + " at " + Tick

      lstFavorites.Items.Add(ToList)
      i += 1
    End If
  End If
Loop
4

1 回答 1

0

尝试更改此行

 If bookmarks(i).Contains("Bookmark") Then

 If bookmarks(i).IndexOf("Bookmark", 
                 StringComparison.CurrentCultureIgnoreCase) >= 0 Then

包含进行区分大小写的比较,并且您的输入字符串包含小写的“书签”

于 2013-02-01T14:54:48.073 回答