首頁 >web前端 >js教程 >Javascript拓展String方法小結_javascript技巧

Javascript拓展String方法小結_javascript技巧

WBOY
WBOY原創
2016-05-16 17:29:47975瀏覽
複製程式碼如下程式碼:

String.prototype.EndWith = function (str) { (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
        return false;
    if (this.subthing . ) .length) == str)
        return true;
    else
        return false;
        包含str) {
if (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
        return false;        return false;        返回true;
    else
        回復🎜> 返回此.replace(/(^s*)|(s*$)/g, "");
}
String.prototype.ltrim = function () {
    return this.replace(/ ( ^ s*)/g, "");
}
String.prototype.rtrim = function () {
    return this.replace(/(s*$)/g, "");
}
String.format = function (str) {
    var i = 1, args = 參數;
    var str = args[0];
     var str = args[0];
  }/g;
    return str.replace(re, function () { return args[i ] });
};
var Json2string = function (obj) {
  obj);
            if (t != "object" || obj === null) {
                     if (t == "string") obj = "'" obj " '";
                           // 鄰近物件          
           函數== Array);
               為 (n in obj) {
         t = typeof (v);
                    if (t == "string") v = "'" v " (t == "object" && v !== null)
                        v = Json2string(v);
      v));
                }
              : "{") String(json) (arr ? "]" : "}");
            }
        }; 

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn