| | |
string tokenizer
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Java Syntax (Toggle Plain Text)
void function() { while (true) { System.out.println("I was too lazy to do my own homework so I got this piece of code off the web!"); } }
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
To help get you started:
Java Syntax (Toggle Plain Text)
import java.util.*; public class Playing { public static void main(String[] args) { String ip = new String("127.0.0.1"); StringTokenizer st = new StringTokenizer(ip, "."); while (st.hasMoreTokens()) { // your code here System.out.println("token: " + st.nextToken()); } } }
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/
Bored? Visit http://www.kaelisspace.com/
•
•
•
•
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.
*Voted best profile in the world*
I assume someone needs to tell the teacher that. LOL
I was wondering why one wouldn't just regex for validation.
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/
Bored? Visit http://www.kaelisspace.com/
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).
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.
•
•
Join Date: Feb 2007
Posts: 4
Reputation:
Solved Threads: 0
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.
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.
•
•
•
•
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.
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
----------------------------------------------
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
![]() |
Similar Threads
- Java's String Tokenizer (Java)
- string tokenizer (ASP)
- String Tokenizer Help (Java)
- Java with String Tokenizer (Java)
Other Threads in the Java Forum
- Previous Thread: how use integer values begins with zero
- Next Thread: persisting the session
| Thread Tools | Search this Thread |
Tag cloud for Java
addressbook android api apple applet application arguments array arrays automation binary bluetooth button calculator chat class classes client code columns component converter database draw eclipse error errors event exception file fractal ftp game givemetehcodez graphics gridlayout gui helpwithhomework html ide image inetaddress input integer j2me japplet java javaprojects jme jmf jni jpanel julia link linux list loop map method methods midlethttpconnection mobile netbeans newbie number objects openjavafx oracle php print problem program programming project projects recursion rim scanner screen server set signing size smart sms socket sort sql storm string support swing test threads time tree unlimited variablebinding webservices windows






