Never been to DZone Snippets before?

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

About this user

Thiti V. Sintopchai http://thitiv.blogspot.com

« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS 

Java: RegEx: Splitting a space-, comma-, and semi-colon separated list

// Greedy RegEx quantifier used
// X+ = X, one or more times
// [\\s,;]+ = one or more times of either \s , or ;

   1  
   2      String test_data = "hello world, this is a test, ;again";
   3      _logger.debug("Source: " + test_data);
   4      
   5      for (String tag : test_data.split("[\\s,;]+"))
   6      {
   7        _logger.debug("Received tag: [" + tag + "]");
   8      }

Java: RegEx to Remove HTML Tags

// Ref: https://jalbum.net/forum/thread.jspa?forumID=7&threadID=971&messageID=6907

   1  
   2  String noHTMLString = htmlString.replaceAll("\\<.*?\\>", "");

JavaScript: String Tokenization and Substring

// Tokenize a comma-separated string
// then recreate the comma-separated list

   1  
   2    var currentTagTokens = currentTags.split( "," );
   3    var existingTags = "";
   4  
   5    for ( var i = 0; i < currentTagTokens.length; i++ )
   6    {
   7      existingTags = existingTags + currentTagTokens[ i ] + ", ";
   8    }
   9  
  10    // Remove the trailing ", " from existingTags
  11    existingTags = existingTags.substring( 0, existingTags.length - 3 ); 

Java: Reading String from a File

// Ref: http://www.exampledepot.com/egs/java.util.regex/Comment.html

   1  
   2      try {
   3          File f = new File("pattern.txt");
   4          FileReader rd = new FileReader(f);
   5          char[] buf = new char[(int)f.length()];
   6          rd.read(buf);
   7          patternStr = new String(buf);
   8      
   9          matcher = pattern.matcher(inputStr);
  10          matchFound = matcher.matches();
  11      } catch (IOException e) {
  12      }

JavaScript String Tokenization

//
// String Tokenization with JavaScript
// From http://www.thescripts.com/forum/thread91795.html
//

   1  
   2  function makeArray( strLongString )
   3  {
   4    return strLongString.split( "," );
   5  }

JavaScript String Comparison

// Example use
// if (isSameString(tags, "_none_")) ...

   1  
   2        function isSameString( s1, s2 )
   3        {
   4          alert( "s1: " + s1.toString() );
   5          alert( "s2: " + s2.toString() );
   6  
   7        	if ( s1.toString() == s2.toString() )
   8          {
   9        	  return true;
  10          }
  11          else
  12          {
  13            return false;
  14          }
  15        }
« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS