Reputation: 349
I'm working on a little side project and I need to turn a string like this: ab c de f g
to an array like so: ab,c,de,f,g I have tried using
Dim string As String = "ab c de f g"
Dim charArray() As Char = string.ToCharArray
but that splits EVERY character into the array (a,b, ,c, ,d,e, ,f, ,g), how can I make it only split between the spaces?
Upvotes: 0
Views: 1625
Reputation: 216293
It seems a job for String.Split
Dim source As String = "ab c de f g"
Dim result AS String() = source.Split(" "c)
For Each s in result
Console.WriteLine(s)
Next
Upvotes: 1
Reputation: 3
I would read the entire string and use the space as delimeter. Means: create a pointer to the string and skip till you find character, then use strncpy, to copy the substring you need. repeat it while(*ptr).
Upvotes: 0