samedi 28 février 2015

How to find the delimiter encountered in a string in JAVA

I have written simple program in Java which does manipulation of a given string.


The input string has some delimiters which are non-alphabets. I have used String Tokenizer to read and manipulate the individual words in a string.


Now I need to reconstruct this manipulated string with the same set of delimiters. Appreciate if any one can suggest me how to identify the delimiter.


In other words, this is what input is:


Text1 Text2 Text3 Text4 This is what my code does:


NewText1 NewText2 NewText3 NewText4


I made use of string tokenizer to identify the next token in this manner: StringTokenizer st = new StringTokenizer(str, ", 0123456789(*&^%$#@!-_)");


But now I would like to identify the delimiter that was encountered so that I can build my new string.


This is what I actually want:


NewText1 Delimiter1 NewText2 Delimiter2 NewText3 Delimiter3 NewText4 Delmiter4


Aucun commentaire:

Enregistrer un commentaire