• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

parsing the whole string in seperate word

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.javaworld.com/javaworld/javatips/jw-javatip112.html
Check out the url given to find the solution to your problem
-arun
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Darshan Bhavsar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic