How can I split a string without know the seperator?

DeltaWolf7

Well-known member
Joined
Jan 21, 2006
Messages
47
Programming Experience
Beginner
If i have a list of string like this;

000.000.000.000 <1 space> www.msn.com
000.000.000.001 <3 spaces> www.something.net
000.000.000.002 <2 spaces> www.new.co.uk
000.000.000.003 <3 spaces> www.new.co.uk

ETC. Note the space are actual spaces in the real thing, the number showing how many between ip and hostname.

How can I split these up so that I can make a word list from them?

I would like the output to be something like this;

msn|1
something|1
new|2

ETC, plus the number of time they occured seperated someway.

I made a program to do this in Visual DialogScript, but in vb.net it seems to be complicated to me.

Thank you
 
String.Split is overloaded. The following code will popup two messages that both say "2":
VB.NET:
Dim str1 As String = "Hello World"
Dim str2 As String = "Hello   World"

MessageBox.Show(str1.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries).Length.ToString())
MessageBox.Show(str2.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries).Length.ToString())
 
You could also use regular expressions:
VB.NET:
Dim strLine as String = "a b    c  d 1 2   3"
Dim strSplit() as String = System.Text.RegularExpressions.RegEx.Split(strLine, " +")
Remember there's a space before the plus sign. The " +" is a regular expression. If you want to split it not just based on spaces, maybe periods, spaces, and slashes, you could use something like "[ ./]+" instead of " +". Then if you had "a.b.c d.1/2//3", you would still get an array like {a,b,c,d,1,2,3}.
 
Back
Top