• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Split() String Tokenizer question

 
Ray Zeigler
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ray Zeigler
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
=) 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?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic