string tokenizer

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2007
Posts: 2
Reputation: mengani123 is an unknown quantity at this point 
Solved Threads: 0
mengani123 mengani123 is offline Offline
Newbie Poster

string tokenizer

 
0
  #1
Feb 23rd, 2007
please helpme to write a funtion in java.


write a functionto validate ip address from a given string. using string tokenizer. ex:- 192.160.1.5


please send me the code.


sanjay
sanjay
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: string tokenizer

 
0
  #2
Feb 23rd, 2007
  1. void function() {
  2. while (true) {
  3. System.out.println("I was too lazy to do my own homework so I got this piece of code off the web!");
  4. }
  5. }
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Solved Threads: 4
nikkiH's Avatar
nikkiH nikkiH is offline Offline
Junior Poster in Training

Re: string tokenizer

 
0
  #3
Feb 23rd, 2007
To help get you started:

  1. import java.util.*;
  2.  
  3. public class Playing {
  4.  
  5. public static void main(String[] args) {
  6. String ip = new String("127.0.0.1");
  7. StringTokenizer st = new StringTokenizer(ip, ".");
  8. while (st.hasMoreTokens())
  9. {
  10. // your code here
  11. System.out.println("token: " + st.nextToken());
  12. }
  13.  
  14. }
  15. }
Google is your friend. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: string tokenizer

 
0
  #4
Feb 23rd, 2007
From Java's StringTokenizer API-docs:

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.
i
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Solved Threads: 4
nikkiH's Avatar
nikkiH nikkiH is offline Offline
Junior Poster in Training

Re: string tokenizer

 
0
  #5
Feb 23rd, 2007
I assume someone needs to tell the teacher that. LOL
I was wondering why one wouldn't just regex for validation.
Last edited by nikkiH; Feb 23rd, 2007 at 5:05 pm.
Google is your friend. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: string tokenizer

 
0
  #6
Feb 24th, 2007
probably still using a 1.1 based book...
Or the kid misunderstood the assignment and it said to "tokenise a string", the first thing he found when looking for that was "StringTokenizer" (less likely, as it assumes some initiative on the part of the OP).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 4
Reputation: kashko is an unknown quantity at this point 
Solved Threads: 0
kashko kashko is offline Offline
Newbie Poster

Re: string tokenizer

 
0
  #7
Feb 26th, 2007
Define validate!!!!
Define validate!!!!
Define validate!!!!


Assuming you mean verify it could be a valid IP address even if no one is using it, then you can do this with String Tokenizer or Stream Tokenizer

String tokenizer splits the string into chunks using a delimiter.
You will have to consider IP4 and IP6 formats and at the very least verify the number of chunks is correct and the values of each chunk are in range.

If you mean is there something there when you try to connect that is a whole new ball game and I would suggest thinking carefully why you would want to do that from code.

It is also possible ( and I would look it up if I needed to do so) that sun have built the check you want into their API. In that case use SUN's methods. Chances are they will have done a better job thab you could.




Originally Posted by mengani123 View Post
please helpme to write a funtion in java.


write a functionto validate ip address from a given string. using string tokenizer. ex:- 192.160.1.5


please send me the code.


sanjay
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,415
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 256
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: string tokenizer

 
0
  #8
Feb 26th, 2007
Originally Posted by kashko View Post
Define validate!!!!
Define validate!!!!
Define validate!!!!


Assuming you mean verify it could be a valid IP address even if no one is using it, then you can do this with String Tokenizer or Stream Tokenizer

String tokenizer splits the string into chunks using a delimiter.
You will have to consider IP4 and IP6 formats and at the very least verify the number of chunks is correct and the values of each chunk are in range.

If you mean is there something there when you try to connect that is a whole new ball game and I would suggest thinking carefully why you would want to do that from code.

It is also possible ( and I would look it up if I needed to do so) that sun have built the check you want into their API. In that case use SUN's methods. Chances are they will have done a better job thab you could.
Um, I'm sorry, but what part of "using string tokenizer" did you not understand. I am quite sure the teacher would be satisifed with something that checks that it is four numbers between 0 and 255 seperated by a dot. I am fairly sure that this is a class exercise in the Strings and converting them to ints and not any actual networking exercise.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC