473,395 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

tokenizing strings

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
3 9564
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
* 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Justin L. Kennedy | last post by:
I am looking for a function that takes in a string and splits it using a list of other strings (delimiters) and can return the delimiters as well as the extra parts of the string. I was trying the...
28
by: David Rubin | last post by:
I looked on google for an answer, but I didn't find anything short of using boost which sufficiently answers my question: what is a good way of doing string tokenization (note: I cannot use boost)....
29
by: Jason Curl | last post by:
Hello, Is it legal to have a non-quote terminated string in C? For example: printf("Hello World \n"); instead of what I normally use
11
by: wreckingcru | last post by:
I'm trying to tokenize a C++ string with the following code: #include <iostream> #include <stdio> #include <string> using namespace std; int main(int argc, char* argv)
5
by: Denis Petronenko | last post by:
Hello, how can i read into strings from ifstream? file contains values in following format: value11; val ue12; value 13; valu e21;value22; value23; etc. i need to read like file >string,...
8
by: Acolyte | last post by:
Ok, the program I'm working on now involves taking an input string and tokenizing it, by seperating it by spaces. Here's what I've got: #include <stdio.h> #include <string.h> int main (void) {...
8
by: Ulysse | last post by:
Hello, I need to clean the string like this : string = """ bonne mentalit&eacute; mec!:) \n <br>bon pour info moi je suis un serial posteur arceleur dictateur ^^* \n ...
8
by: arnaudk | last post by:
Hello, I need to get the following string "12332321213,SomeText,3.141592654" into constituent variables: an unsigned long int, a string and a double. So far I have, string line =...
6
m6s
by: m6s | last post by:
1. After hours of researching, I used these snippets : void Object::TokenizeLines(const string& str, vector<string>& tokens, const string& delimiters) // Skip delimiters at beginning....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.