473,385 Members | 1,732 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,385 software developers and data experts.

Tokenize a string in C#

Hi,

I am looking for a stringtokenizer class/method in C#, but can't find one.
The similar classes in Java and C++ are StringTokenizer and
CStringT::tokenize respectively. I need to keep a current position within the
string and change the delimiters dynamically when going throught the string.
Does anyone know a stringtokenizer in c#?

Thanks a lot,

James
Nov 17 '05 #1
2 31359
James <Ja***@discussions.microsoft.com> wrote:
I am looking for a stringtokenizer class/method in C#, but can't find one.
The similar classes in Java and C++ are StringTokenizer and
CStringT::tokenize respectively. I need to keep a current position within the
string and change the delimiters dynamically when going throught the string.
Does anyone know a stringtokenizer in c#?


I don't believe there is one - most cases are handled simply using
String.Split, but obviously that doesn't let you change delimiters
dynamically.

Personally I've always found it hard to predict *exactly* what happens
when changing delimiters with Java's StringTokenizer, but maybe that's
just me.

It shouldn't be too hard to write your own one though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
Maybe something along the lines of:

string NextToken (out string Tail, string Tokens, params char[] Separator)
{return NextToken (out Tail, Tokens, true, Separator) ;}
string NextToken (out string Tail, string Tokens, bool Trim, params char[]
Separator)
{
Tail = null ;
if (Tokens == null) return null ;
string [] Pieces = Tokens.Split (Separator, 2) ;
if (Pieces.Length > 1) Tail = Trim ? Pieces[1].Trim () : Pieces[1] ;
return Trim ? Pieces[0].Trim () : Pieces[0] ;
}

"James" <Ja***@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
Hi,

I am looking for a stringtokenizer class/method in C#, but can't find one.
The similar classes in Java and C++ are StringTokenizer and
CStringT::tokenize respectively. I need to keep a current position within
the
string and change the delimiters dynamically when going throught the
string.
Does anyone know a stringtokenizer in c#?

Thanks a lot,

James

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: qwweeeit | last post by:
In analysing a very big application (pysol) made of almost 100 sources, I had the need to remove comments. Removing the comments which take all the line is straightforward... Instead for the...
9
by: Lans | last post by:
I have a string that I need to tokenize but I need to use a string token see example i am trying the following but strtok only uses characters as delimiters and I need to seperate bu a certain...
4
by: Kelvin | last post by:
hi: in C, we can use strtok() to tokenize a char* but i can't find any similar member function of string that can tokenize a string so how so i tokenize a string in C++? do it the C way? ...
5
by: Lam | last post by:
Hi I try to read in a line from text file, and how can I tokenize the line? Thanks
20
by: bubunia2000 | last post by:
Hi all, I heard that strtok is not thread safe. So I want to write a sample program which will tokenize string without using strtok. Can I get a sample source code for the same. For exp:...
1
by: Tim | last post by:
I ran into a problem with a script i was playing with to check code indents and need some direction. It seems to depend on if tabsize is set to 4 in editor and spaces and tabs indents are mixed on...
0
by: noobcprogrammer | last post by:
#include "IndexADT.h" int IndexInit(IndexADT* word) { word->head = NULL; word->wordCount = 0; return 1; } int IndexCreate(IndexADT* wordList,char* argv)
2
by: askalottaqs | last post by:
there's in maya's scripting language mel, called tokenize, you simply tokenize("string i want to tokenize"," ",bufferArray) which will fill the fufferArray wih the first string tokenized accorfing...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.