类解析字符串列表

类解析字符串列表

本文介绍了使用list()类解析字符串列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用List()类的字符串的示例列表:
List()

"001","003","005","008","040","a","b","043","a","949","w","r"
我想输出整数和之后的任何字符.因此,上述字符串的示例输出为:

001
003
005
008
040 a b
043 a
949 wr

我的输出的休闲代码如下:

Example list of string using List() class:
List()

"001","003","005","008","040","a","b","043","a","949","w","r"
I would like to output integers and any characters after. So the example output from string above will be:

001
003
005
008
040 a b
043 a
949 w r

The fallowing code my output looks like:

For Each node As TreeNode In nodes
            If node.Checked Then list.Add(node.Name.ToString)
            '' list.Add("|")
            GetSelectedNodes(node.Nodes, list)

        Next


        '' Loop through list with a for to loop.
        Dim i As Integer

        For i = 0 To list.Count - 1


            MsgBox(list.Item(i))


        Next i


输出:
001
003
005
008
040
a
b
043
a
949
w
r
帮助正确的方向说明如何获取整数和之后的任何字符.感谢您的帮助.
[edit]已添加代码块-OriginalGriff [/edit]


Output:
001
003
005
008
040
a
b
043
a
949
w
r
Help toward the right directions on how to get integers and any character after. Appreciate your help.
[edit]Code block added - OriginalGriff[/edit]

推荐答案


Dim lstNumbersAndLetters As New List(Of String) 'This is your list
Dim lstFinalOutput As New List(Of String) 'This is the final output

For Each strItem As String In lstNumbersAndLetters
    If IsNumeric(strItem) Then
        'this is a number, so create a new item
        lstFinalOutput.Add(strItem)
    Else
        'this is a letter, tack it onto the previous item
        lstFinalOutput.Item(lstFinalOutput.Count - 1) = lstFinalOutput.Last & " " & strItem
    End If
Next



您也可以使用 [ ^ ].



You could also look into using regular expressions[^] somehow.



这篇关于使用list()类解析字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 23:20