Results 1 to 2 of 2
Thread: String Tokenizer
- 03-09-2010, 12:44 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 16
- Rep Power
- 0
String Tokenizer
Alrighty, I'm making a program that will accept a couple commands on one line, seperated by white spaces. Here are some of the commands,
Right now im using sting tokenizer, and spliting up those 3 tokens and storing them into strings.Java Code:a <setNumber> <movieName> Add a movie to a set r <setNumber> <movieName> Remove a movie to a set m <setNumber> <movieName> Checks if a movie is in a set
But the problem I have is that a movie title can contain more than one token, so this is what I had to do...
It will store tokens into a string for a movie title up to 7 words long lol.... Is there an easier way to be doing this? This looks really messy/sloppy. Thanks.Java Code:if (st.hasMoreTokens()) //This is the command s1 = st.nextToken(); if (st.hasMoreTokens()) //This is the set number I later parse to an int s2 = st.nextToken(); if (st.hasMoreTokens()) //Here is where movie title starts s3 = st.nextToken(); if (st.hasMoreTokens()) s4 = st.nextToken(); if (st.hasMoreTokens()) s5 = st.nextToken(); if (st.hasMoreTokens()) s6 = st.nextToken(); if (st.hasMoreTokens()) s7 = st.nextToken(); if (st.hasMoreTokens()) s8 = st.nextToken(); if (st.hasMoreTokens()) s9 = st.nextToken();
- 03-09-2010, 01:14 PM #2
Not great, but a little better?
Java Code:if (st.hasMoreTokens()) //This is the command s1 = st.nextToken(); if (st.hasMoreTokens()) //This is the set number I later parse to an int s2 = st.nextToken(); while (st.hasMoreTokens()) //Here is where movie title starts s3 = s3 + " " + st.nextToken();
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Similar Threads
-
String Tokenizer
By redasu in forum Advanced JavaReplies: 4Last Post: 02-19-2010, 03:30 AM -
Manipulating String Tokenizer
By Bomber_Will in forum New To JavaReplies: 2Last Post: 04-19-2009, 11:54 PM -
string tokenizer
By twinytwo in forum New To JavaReplies: 2Last Post: 03-26-2009, 02:10 PM -
Problem with string tokenizer
By twinytwo in forum AWT / SwingReplies: 2Last Post: 03-26-2009, 11:27 AM -
question on string tokenizer
By munigantipraveen in forum New To JavaReplies: 2Last Post: 05-23-2008, 05:00 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks