使用list()类解析字符串列表 [英] Parse list of strings using list() class
问题描述
使用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]
推荐答案
您可能会发现本文有用:
持久性字符串解析器 [
You might find this article useful:
Persistent String Parser[^]
您可能想看看IsNumeric函数 [
You might want to look at the IsNumeric function[^]. It would be one method of accomplishing your goal, but I''m not sure how efficient it is.
---Updated solution:
I was thinking you would use it sort of like this:
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.
感谢所有评论我要走另一条路,尝试使用string-builder()和string()类解决此问题.
Thanks for all the comments I am going go in a different route, I going to try using the string-builder() and the string() class for this issue.
这篇关于使用list()类解析字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!