• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hi  RSS feed

 
Sobhan Hota
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following problem.
I have a sting with content. Using String Tokenizer how can i get 3 tokens. Token(here) - Each block of sentences which are separated by an blankline.
I am NN boy yar
am am a boy yar
a am NN boy yar
boy am NN boy yar
. am NP boy yar
I am goingI am going
I am goingI am going
I am goingI am going
Once am a boy 0
he am a boy 0
was am a boy 0
held am a boy 0
for t t t t

thanks and regds
Sobhan
 
Abdul Narayan D'souza TP
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sobhan,
I guess u cannot do it with StringTokenizer.
 
Abdul Narayan D'souza TP
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sobhan,
I guess u cannot do it with StringTokenizer.
U could use LineNumberReader, and check if the returned line is blank.
Anyways u r in the wrong forum,this one deals puerly with "Threads and Synchronization"
Hey bartender where art thou.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As this particular festival of emoticons is wholly unrelated to "Threads and Synchronization" (the topic of this forum) I'll be moving it to "Java in General (Intermediate)." Followups there, please.
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sobhan,
I would break this problem down into smaller pieces. First, I'd forget about the file part: pretend you've already read in the information from the File, and just want to use StringTokenizer.
After you get that piece working, working on getting the information from the file, and feed it to the above method, which you already know works. Thus, try the following


Thus, first implement getTokens(). Then, after it's working perfectly, implement getFileContent()
Good luck,
M
 
Rebecca Hopper
Ranch Hand
Posts: 38
Eclipse IDE jQuery Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go to the Java API documentation at http://java.sun.com/j2se/1.4.2/docs/api/ and look up the StringTokenizer class. It's in the java.util package. If you write some code and it doesn't work, post it & people will help you figure out why.
 
Byron Estes
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that your problem is beyond the vanilla implementation of the StringTokenizer because the StringTokenizer only works with single String characters acting as the delimiter. If you pass in a String with multiple characters it assumes that you want a tokenizer not based upon the character series, but that each character in the string is it's own separate delimiter character (i.e. you want to break on every instance of every character in the delimiter string).
In reality you want to break on the occurance of two newline characters in sequence (...or something like that). Because the StringTokenizer can only deal with delimiters made up of a single character, not the occurence of a set of characters in sequence, it won't work for you.
I've written my own StringTokenizer class that can use multi-character delimiters and I'm sure there are classes out there in open source that do similar things.
Good Luck,
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Byron,
Unless I miss my guess, this is a homework assignment, so we can probably count well behaved data.
M
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!