0

我正在尝试删除 ListBox 中所有 Line Items 中的所有空格。我本来以为我可以只输入一个标准化空白函数,但事实并非如此。长话短说,我正在尝试编写一个程序来计算文件中 XML 字段的数量。我想显示所有字段,但取消它前面的所有间距(因为它被格式化为 XML)。

'Imports System.IO
Public Class Form1
    Dim theFile As StreamReader
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadTheFile.Click

        'Load the File
        theFile = New StreamReader("C:\Users\Marc Wilson\Documents\XML\sampledata.xml")

        While (theFile.Peek > -1)

            ListBox1.Items.Add(theFile.ReadLine)

        End While
        theFile.Close()

        'Only get the fields
        Dim numberOfLines As Integer = ListBox1.Items.Count
        For i = 0 To numberOfLines - 1

            Dim theLineItem As String = ListBox1.Items.Item(i).ToString
            If theLineItem.Contains("<my:") And theLineItem.Contains("/>") Then
                ListBox2.Items.Add(theLineItem)
            End If
        Next   

        'Count items
        lblCount.Text = ListBox2.Items.Count.ToString

    End Sub   
End Class
4

1 回答 1

1

这将删除前导和尾随空格

theFile.ReadLine.trim
于 2013-06-06T01:15:59.123 回答