I have string like String s="171734---------printer-head.-----No"; i want to break this string into words separeted with --- Means i want output as following word1=171734 word2=--------- word3=printer-head. word4=----- word5=No How could it possible ,i know with StringTokenizer it is possible but i am not able to get it. Please help me out. Any help is appreceated Thanks in advance
could you be more specific on the format of the string? [NUMBERs][-s][LETTERs][-s][LETTERs] and you dont know the size of each token, right? is the length of the string fixed? the [-s] is always >= 3? and in your example, printer-head, has a "-". will it always be like this, 1 "-", or just in some cases. please be specific.
Thanks for reply String format is like MR_____Has____hand
Underscores are considered as blank so i want output format like MR DARSHAN has ONE hand so underscores token should be replaced with random string .This underscores tokens are not fixed. So first i want to calculate no of blanks in between the words then replace this blanks with some predefined String Thanks once again [ January 31, 2002: Message edited by: Darshan Bhavsar ]
Use the following form of the string tokenizer - StringTokenizer(String str, String delim, boolean returnDelims) If the boolean is true, delimiter characters are themselves considered to be tokens. A token is either one delimiter character, or a sequence of consecutive characters that are not delimiters. StringTokenizer st = new StringTokenizer(inputstring, "-", true); while (st.hasMoreTokens()) {
\\process tokens } Hope this helps.
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
Gift giving made easy with the permaculture playing cards