Home arrow static arrow Java Programming [Archive] - String Processing....
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - String Processing....
This topic has 13 replies on 1 page.

Posts:37
Registered: 5/11/04
String Processing....  
Jul 21, 2004 8:08 AM



 
Hello:
Can we process the string input (for eg) "java is a perfect OOPs" as
java
is
a
perfect
oops
without using StringTokenizer? Any suggestion....
 

Posts:59
Registered: 6/28/04
Re: String Processing....  
Jul 21, 2004 8:13 AM (reply 1 of 13)



 
[url=http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#split(java.lang.String)]split[/url]
 

Posts:87
Registered: 00-05-05
Re: String Processing....  
Jul 21, 2004 8:14 AM (reply 2 of 13)



 
Sure you can. You would use methods from the String class,
such as the "toLowerCase", "indexOf" and "substring" methods. But you would
basically be rewriting the StringTokenizer.
 

Posts:87
Registered: 00-05-05
Re: String Processing....  
Jul 21, 2004 8:15 AM (reply 3 of 13)



 
yeah, split would work also, and is a better way
 

Posts:2,399
Registered: 10/26/00
Re: String Processing....  
Jul 21, 2004 8:41 AM (reply 4 of 13)



 
java.io.StreamTokenizer is a rather efficient, configurable tokenizer.
 

Posts:59
Registered: 6/28/04
Re: String Processing....  
Jul 21, 2004 8:49 AM (reply 5 of 13)



 
Perhaps the original poster can give us the smallest of hints as to why he doesn't want to use
StringTokenizer.
 

Posts:24,036
Registered: 2/3/03
Re: String Processing....  
Jul 21, 2004 8:57 AM (reply 6 of 13)



 
Perhaps the original poster can give us the smallest
of hints as to why he doesn't want to use
StringTokenizer.

Because String.split() is preferred to StringTokenizer... :o)
 

Posts:37
Registered: 5/11/04
Re: String Processing....  
Jul 21, 2004 9:07 AM (reply 7 of 13)



 
Its working great...Thanks all for your tips.....
 

Posts:59
Registered: 6/28/04
Re: String Processing....  
Jul 21, 2004 9:32 AM (reply 8 of 13)



 
Perhaps the original poster can give us the smallest of hints as to why it couldn't work great with a StringTokenizer.
 

Posts:37,103
Registered: 3/30/99
Re: String Processing....  
Jul 21, 2004 9:38 AM (reply 9 of 13)



 
Perhaps the original poster can give us the smallest
of hints as to why he doesn't want to use
StringTokenizer.

Because the homework assignment said, "Don't use StringTokenizer"?
 

Posts:24,036
Registered: 2/3/03
Re: String Processing....  
Jul 21, 2004 9:43 AM (reply 10 of 13)



 
"StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead."
 

Posts:59
Registered: 6/28/04
Re: String Processing....  
Jul 21, 2004 9:49 AM (reply 11 of 13)



 
But if the original poster had read than on the javadoc page for StringTokenizer why didn't he look
at the next line, where the split solution is demonstrated?
 

Posts:24,036
Registered: 2/3/03
Re: String Processing....  
Jul 21, 2004 10:08 AM (reply 12 of 13)



 
But if the original poster had read than on the
javadoc page for StringTokenizer why didn't he look
at the next line, where the split solution is
demonstrated?

Beats the tar outta me. I was just throwing in my $0.02 about StringTokenizer - I certainly wasn't attempting to explain the OP's request for homework assistance... :o)
 

Posts:11,200
Registered: 7/22/99
Re: String Processing....  
Jul 21, 2004 10:49 AM (reply 13 of 13)



 
java.io.StreamTokenizer is a rather efficient,
configurable tokenizer.

I really wouldn't call that mess "configurable" ...
 
This topic has 13 replies on 1 page.