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
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.
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.
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
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.
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,