拓展了几个常用的方法
需要的朋友可以参考下
复制代码 代码如下:
StringprototypeEndWith = function (str) {
if (str == null || str == "" || thislength == || strlength > thislength)
return false;
if (thissubstring(thislength strlength) == str)
return true;
else
return false;
return true;
}
StringprototypeStartWith = function (str) {
if (str == null || str == "" || thislength == || strlength > thislength)
return false;
if (thissubstr( strlength) == str)
return true;
else
return false;
return true;
}
StringprototypeTrim = function () {
return thisreplace(/(^s*)|(s*$)/g "");
}
Stringprototypeltrim = function () {
return thisreplace(/(^s*)/g "");
}
Stringprototypertrim = function () {
return thisreplace(/(s*$)/g "");
}
Stringformat = function (str) {
var i = args = arguments;
var str = args[];
var re = /{(d+)}/g;
return strreplace(re function () { return args[i++] });
};
var Jsonstring = function (obj) {
var t = typeof (obj);
if (t != "object" || obj === null) {
// simple data type
if (t == "string") obj = "" + obj + "";
return String(obj);
}
else {
// recurse array or object
var n v json = [] arr = (obj && objconstructor == Array);
for (n in obj) {
v = obj[n]; t = typeof (v);
if (t == "string") v = "" + v + "";
else if (t == "object" && v !== null)
v = Jsonstring(v);
jsonpush((arr ? "" : "" + n + ":") + String(v));
}
return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
}
};