Splitting a string with unknown amount of spaces

rusty009

Member
Joined
May 27, 2010
Messages
5
Programming Experience
1-3
Hey, I have a string which I have pulled out of a text file as shown below,

s= “ 49.026 4.591 410.204 399.212 410.505 407.504 1.536”
and I would like to split it up and get the numbers into individual string() arrays. I have tried using split(“ ”) , but the problem with this is that it only splits up characters with one space between them, and there could be multiple spaces between characters so it ends up storing blank spaces it a string array. This is my code,

VB.NET:
dim s as String = “  49.026   4.591 410.204 399.212 410.505 407.504   1.536”
dim words As String() = s.split(“ “)

Thanks
 
You could specify that empty entries should be removed:
VB.NET:
result = s.Split(" ".ToCharArray, StringSplitOptions.RemoveEmptyEntries)
 
You could specify that empty entries should be removed:

Code:
result = s.Split(" ".ToCharArray, StringSplitOptions.RemoveEmptyEntries)

Thanks, I will try it when i get home. However, say I wanted to split up data with a "." and some values had multiple "." characters between them, for instance

one.two..three...four

how would I go about doing this ? Thanks.
 
Exactly the same, "." is char just like the space " " char.
 
Back
Top