Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

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]
Posted
Updated 16-May-11 8:22am
v2
Comments
OriginalGriff 16-May-11 14:26pm    
Sorry, but that doesn't make a whole lot of sense.
Do I take it that you have a TreeView with nodes, arranged so that "a" and "b" are subnodes of "040", and "a" is a subnode of "043", and so forth? You then parse the tree, and convert it into a flat List.
If so, what is the problem? What are you actually trying to do once you have the tree?

You might find this article useful:

Persistent String Parser[^]
 
Share this answer
 
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:

VB
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.
 
Share this answer
 
v2
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.
 
Share this answer
 
By searching google or any search engine site.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900