JS implementation similar to the PHP trim method

Source: Internet
Author: User

Var trim = function (A, b) {    var a = a ? a :   " ";    var b = b ? b :  "";     if  (b ==  "") {return  "";     }    var  la = a.length;    var lb = b.length;     var s = e = false;     if (B.indexOf (a)  === 0 ) {    s = true;    }    if (b.lastIndexOf (a)  === lb-la)  {e = true;    }    var r  = b;    if  (e)  {if  (r.length > 0)  {r =  r.substring (0,lb-la); Return trim (a,r);}  else {    return  "";}     }    if  (s)  {if  (r.length > 0)  {    r =  r.substring (la,r.length);     return trim (A, r);}  else {    return  "";}     }    return r;}

JS does not like the PHP trim method, its own implementation of a, convenient for personal use. If before me the cattle have been fulfilled, and the thought is consistent, please do not laugh. Coincidence, because I did not learn from anyone.

This article is from the "Rhino" blog, please make sure to keep this source http://rhino.blog.51cto.com/5504750/1761971

JS implementation similar to the PHP trim method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.