【问题标题】:Remove Whitespace from Line Item in ListBox (VB)从列表框中的行项目中删除空格(VB)
【发布时间】:2013-06-06 14:46:00
【问题描述】:

我正在尝试删除列表框中所有行项目中的所有空格。我本来以为我可以只输入一个规范化空白函数,但事实并非如此。长话短说,我正在尝试编写一个程序来计算文件中 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

【问题讨论】:

    标签: vb.net listbox whitespace


    【解决方案1】:

    这将删除前导和尾随空格

    theFile.ReadLine.trim
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-07
    • 2010-11-29
    相关资源
    最近更新 更多