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.

  1. // here is the function splitrim
  2. String.prototype.splitrim = function(t){
  3. return this.trim().split(new RegExp(’\\s*’+t+’\\s*’))
  4. }
  5.  
  6. //from here is the test code for splitrim
  7. str = ‘ Hello, World! Only a test. ‘;
  8. var arr = str.splitrim(’,’);
  9. document.write (’“’ + arr[0] + ‘”’);
  10. document.write (’“’ + arr[1] + ‘”’);
  11. document.write (’“’ + arr[2] + ‘”’);
  12. 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
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