This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Split() String Tokenizer question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Split() String Tokenizer question" Watch "Split() String Tokenizer question" New topic

Split() String Tokenizer question

Ray Zeigler

Joined: Jul 06, 2012
Posts: 18
im trying to have my server report back a string that tells the client how many integers and non-integer words were in the previous message.
)For example I send the following message from my client to my server "Hi today is July 6"
I want my server to return a string "4 1"
Indicating that the incoming string has 4 non integer words and 1 integer.

Can someone show me the code of how to do this?
I know I can use Split() or String Tokenizer but I cant figure out how to do it

This is my code
M Massa

Joined: Sep 03, 2010
Posts: 7
Ray Zeigler

Joined: Jul 06, 2012
Posts: 18
Say for instance I wanted it to do this count not from a phrase as you showed previously but instead from the data received in the server from the client. How would the code look for something like that?

String Str= new String(receivePacket.getData());
System.out.println("The received string was: " + Str);
System.out.println("It contains: " + numInts
+ " num of Integers and " + numNonInts + " number of Non Integers");

Ray Zeigler

Joined: Jul 06, 2012
Posts: 18
=) Sorry for my silly previous reply.. it was much easier than I thought.
This is what I came up with.. Does it appear proper to you?

I agree. Here's the link:
subject: Split() String Tokenizer question
It's not a secret anymore!