DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
JavaScript: String Tokenization And Substring
// Tokenize a comma-separated string
// then recreate the comma-separated list
var currentTagTokens = currentTags.split( "," );
var existingTags = "";
for ( var i = 0; i < currentTagTokens.length; i++ )
{
existingTags = existingTags + currentTagTokens[ i ] + ", ";
}
// Remove the trailing ", " from existingTags
existingTags = existingTags.substring( 0, existingTags.length - 3 );






Comments
Snippets Manager replied on Wed, 2006/08/02 - 11:16am
Peter Venkman replied on Thu, 2007/03/01 - 8:42am
alert( "one,two,three,four,five".split(",").join(", ") );