954,153 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Tokenize

hello guyz,,who knows how to tokenize???i mean,,i am about to start to make "String Calculator" but i don't know how to tokenize,,,do you know any sites that could explain best about tokens??thank you ahead,,,,

letlet_pogs
Light Poster
44 posts since Aug 2008
Reputation Points: 6
Solved Threads: 1
 

How do you need your tokens to be parsed?

An example...

public class TokenMaster{
	public static void main(String... args){
		String myReallyBIGString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
					 			 + "ALPHABETICAL!\n"
					 			 + "SOMETIMES I FEEL I'VE GOT TO 'AH-AH' RUN AWAY, I'VE GOT TO... "
					 			 + "'AH-AH' GET AWAY!!!\n"
					 			 + "RING RING RING RING RING RING RING... BANANA PHONE! 'doot, doot doot doot doot doot'"
					 			 + "DING-DONG DING-DONG DING-DONG DING... BANANA PHONNNNNE!!!!!";

		String tokens[] = myReallyBIGString.split("\n"); // each token is determined by the newline character

		for(String element : tokens)
			System.out.println(element); // printing the individual tokens generated from String.split("\n")

		System.out.println("\nTokens counted: " + tokens.length);
	}
}
Alex Edwards
Posting Shark
972 posts since Jun 2008
Reputation Points: 392
Solved Threads: 109
 

thank you very much,,,may i as,,how useful are tokens???

letlet_pogs
Light Poster
44 posts since Aug 2008
Reputation Points: 6
Solved Threads: 1
 

you can also use String Tokenizer class.

yilmazhuseyin
Light Poster
48 posts since Oct 2006
Reputation Points: 31
Solved Threads: 5
 
you can also use String Tokenizer class.

Or not, because StringTokenizer is considered an Obsolete class that receives no further support in future releases.

Furthermore, String.split() is better because it takes regular expressions into consideration. StringTokenizer does not.

Alex Edwards
Posting Shark
972 posts since Jun 2008
Reputation Points: 392
Solved Threads: 109
 

You may use the special PHP function strtok

<?php

$myText="online pharmacy web solution";

$strToken=strtok($myText," ");

while($strToken){

echo $strToken."
";

$strToken=strtok(" ");

}

?>
this my hel;p u

digitaldesperad
Newbie Poster
18 posts since Sep 2008
Reputation Points: 10
Solved Threads: 1
 
this my hel;p u


Sure, maybe... if he was using PHP, but since this is the Java forum and his code is Java, your suggestion seems to fall a little bit short of helpful.

And this isn't a chat room, so you can leave the IM-speak at the door.

Ezzaral
Posting Genius
Moderator
15,985 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You