By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,795 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,795 IT Pros & Developers. It's quick & easy.

tokenizing strings

P: n/a
Hello - in Java you have a class called java.util.StringTokenizer that
tokenizes strings, ie

StringTokenizer st=new StringTokenizer("In the beginning "," ",false);
while (st.next())
System.out.println(st.nextToken());

would print out "In", "the", and "beginning", as separate string
tokens, the string being tokenized on the " " (space) character. Is
there a similar utility class in VB.Net.

Chris
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Look up the \*Split\* method in the String class.
Regards
Hexathioorthooxalate
"Christian O'Connell" <cd********@hotmail.com> wrote in message
news:9a**************************@posting.google.c om...
Hello - in Java you have a class called java.util.StringTokenizer that
tokenizes strings, ie

StringTokenizer st=new StringTokenizer("In the beginning "," ",false);
while (st.next())
System.out.println(st.nextToken());

would print out "In", "the", and "beginning", as separate string
tokens, the string being tokenized on the " " (space) character. Is
there a similar utility class in VB.Net.

Chris

Nov 20 '05 #2

P: n/a
* cd********@hotmail.com (Christian O'Connell) scripsit:
Hello - in Java you have a class called java.util.StringTokenizer that
tokenizes strings, ie

StringTokenizer st=new StringTokenizer("In the beginning "," ",false);
while (st.next())
System.out.println(st.nextToken());

would print out "In", "the", and "beginning", as separate string
tokens, the string being tokenized on the " " (space) character. Is
there a similar utility class in VB.Net.


In your case you can use 'Strings.Split' or the string's 'Split' method.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
Christian,
In addition to the others comments:

There are three Split functions in .NET:

Use Microsoft.VisualBasic.Strings.Split if you need to split a string based
on a specific word (string). It is the Split function from VB6.

Use System.String.Split if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter.

Use System.Text.RegularExpressions.RegEx.Split to split based
on matching patterns.

If you are using C#, you can reference the Microsoft.VisualBasic.dll
assembly to use the first function.

Seeing as you want a single space I would recommend String.Split, something
like:

Dim input as String = "In the beginning "
Dim words() as String
words = input.Split(" "c)
For Each word As String in words
Debug.WriteLine(word)
Next

Note the trailing space will cause an empty string to be added to the return
value. You can use String.Trim to remove trailing spaces if needed...

Hope this helps
Jay

"Christian O'Connell" <cd********@hotmail.com> wrote in message
news:9a**************************@posting.google.c om...
Hello - in Java you have a class called java.util.StringTokenizer that
tokenizes strings, ie

StringTokenizer st=new StringTokenizer("In the beginning "," ",false);
while (st.next())
System.out.println(st.nextToken());

would print out "In", "the", and "beginning", as separate string
tokens, the string being tokenized on the " " (space) character. Is
there a similar utility class in VB.Net.

Chris

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.