|
-
Mar 7th, 2009, 04:41 PM
#1
Thread Starter
New Member
[RESOLVED] [2008] Splitting a String with a variable delimiter
Hello. Really been struggling with this one, and i cant seem to find a simple method of doing it...surely there must be one? I have a list of values that i am loading into a variable. I am trying to split that variable by the whitespace that separates each value...the only thing is the whitespace varies in size. eg...
value 1_______________value 2____value 3
value 4__value5____________value6
is there any way of splitting by batches of whitespace?
Thank you
-
Mar 7th, 2009, 04:53 PM
#2
Re: [2008] Splitting a String with a variable delimiter
You could substitute the delimiter out so you only have one and then split the string. You can also do this;
Code:
Dim s As String = "value 1_______________value 2____value 3"
Dim split As Char() = {"_"c}
Dim splits() As String = s.Split(split, System.StringSplitOptions.RemoveEmptyEntries)
For Each str As String In splits
MessageBox.Show(str)
Next
-
Mar 7th, 2009, 04:55 PM
#3
Hyperactive Member
Re: [2008] Splitting a String with a variable delimiter
You could use LINQ for that.
Example.
Code:
Dim value As String = "1 value2 value3"
Dim list = From s In value.Split(" "c) _
Where s.Length > 0
-
Mar 7th, 2009, 05:01 PM
#4
Thread Starter
New Member
Re: [2008] Splitting a String with a variable delimiter
 Originally Posted by Bulldog
You could substitute the delimiter out so you only have one and then split the string. You can also do this;
Code:
Dim s As String = "value 1_______________value 2____value 3"
Dim split As Char() = {"_"c}
Dim splits() As String = s.Split(split, System.StringSplitOptions.RemoveEmptyEntries)
For Each str As String In splits
MessageBox.Show(str)
Next
Fantastic, that worked a charm. Thank you!!
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
|