Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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.
 
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic