|
-
Oct 5th, 2010, 02:26 AM
#10
Fanatic Member
Re: [RESOLVED] String manipulation
 Originally Posted by jmcilhinney
I was hoping that the OP would be able to do some thinking for themselves but, as we're taking that responsibility away from them:
vb.net Code:
Private Function GetSubset(ByVal numbers As String, ByVal startIndex As Integer) As String
Dim superset As String() = numbers.Split(New Char() {","c}, _
StringSplitOptions.RemoveEmptyEntries)
Dim subset As New List(Of String)
For index = startIndex To superset.GetUpperBound(0) Step 3
subset.Add(superset(index))
Next
Return String.Join(",", subset.ToArray())
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str1 = "11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,"
Dim str2 = "11,12,13,14,15,16,17,18,19,20,21,22,23,24,25"
MessageBox.Show(Me.GetSubset(str1, 1 - 1))
MessageBox.Show(Me.GetSubset(str2, 8 - 1))
End Sub
EDIT: Actually, now that I look at the examples provided in the first post, this code won;t do what they indicate is required, although it will do what's actually described in the words of the post.
I like your solution, I should have though of building a list(of string) 
I didn't know about the Step in a for statement so cheers for that
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|