if i have information like this a->b->c->d->MESSAGE,how do i tokenize it such that i get
a,b->c->d->MESSAGE from the original string???????????

if i have information like this a->b->c->d->MESSAGE,how do i tokenize it such that i get
a,b->c->d->MESSAGE from the original string???????????

well ... if you used a StringTokenizer here, with "->" as separator, you wouldn't. you would get
{"a","b","c","d"}

now ... what exactly do you need? do you need the first token, and to add the rest of the input?

then I would suggest using the indexOf("->") and substring(0, locationOfSeparator)
methods from String to get your reply.

(or, still going on tokenizer, but after you printed your first token, you add "," and then all the other tokens separated by the separator)

i want to divide the string into two halves at the first occurence of the delimiter.i hav to do this repeatedly coz at each stage i hav some processing to do on the remaining part of the string

two parts -> or to halves. that's a huge difference.
if I understand it correctly, your most foreward sollution is, as I first suggested, using the indexOf and substring methods.

but, for further posts, let me give you some advice.
don't just ask for sollutions, provide what you have so we can help you improve it. this may come in the form of a piece of code, or your thoughts on what to use, not just the assignment.

its a small component of a large code,I meant two parts.What i have is a message appended with various mac headers acquired at each router it travels through.at the destination i hav to verify each router by taking the mac's one at a time and verifying with the rest of the message. its in the following form a->b->c->d->message.where a is mac header at the router 'a' b is mac at router 'b' and so on.

yeah, ok. but still, if you know up front the substring used as separator, it's quite .. easy to do this with either the indexOf and substring methods, or by hasMoreTokens and nextToken methods.

just try to write this in code. if you don't know how to start, start with a bit of nasi-schneidermann or pseudo-code, that would make it a lot easier to determine what code to use and in what way to use it. it's a lot easier for us to help you improve your code if we get to see it. you don't have to post the entire application, just the code we need to check for errors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.