JavaScript function-Splits the string by given separator and returns an array with trimmed items

pterodactyl-48x48 This extension splits the string by given separator and returns an array with trimmed items. It uses the trim() extension at trim a string from white space by JavaScript function or Another JavaScript function for trim a string from white space.

Regular expressions are a powerful tool for performing pattern matches in Strings in JavaScript.You can perform complex tasks that once required lengthy procedures with just a few lines of code using regular expressions.It is implemented at below function.

// here is the function splitrim
String.prototype.splitrim = function(t){
return this.trim().split(new RegExp(’\\s*’+t+’\\s*’))
}

//from here is the test code for splitrim
str = ‘ Hello, World! Only a test. ‘;
var arr = str.splitrim(’,’);
document.write (’“’ + arr[0] + ‘”’);
document.write (’“’ + arr[1] + ‘”’);
document.write (’“’ + arr[2] + ‘”’);
document.write (’“’ + arr[3] + ‘”’);
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to Ntt.cc

RSS Feed   RSS Feed     Email Feed  Email Feed Follow us Follow us
You can leave a response, or trackback from your own site.

2 Responses to “JavaScript function-Splits the string by given separator and returns an array with trimmed items”

  1. [...] by JavaScript function ( or Another JavaScript function for trim a string from white space ) and JavaScript function-Splits the string by given separator and returns an array with trimmed items, Some Regular expressions have been used. Regular expressions are very powerful tools for [...]

  2. sofa says:

    this does not help

Leave a Reply