亚洲精品中文字幕无乱码_久久亚洲精品无码AV大片_最新国产免费Av网址_国产精品3级片

JavaScript

Javascript拓展String方法代碼

時間:2024-07-15 02:30:11 JavaScript 我要投稿
  • 相關推薦

Javascript拓展String方法代碼

  復制代碼 代碼如下:

  String.prototype.EndWith = function (str) {

  if (str == null || str == "" || this.length == 0 || str.length > this.length)

  return false;

  if (this.substring(this.length - str.length) == str)

  return true;

  else

  return false;

  return true;

  }

  String.prototype.StartWith = function (str) {

  if (str == null || str == "" || this.length == 0 || str.length > this.length)

  return false;

  if (this.substr(0, str.length) == str)

  return true;

  else

  return false;

  return true;

  }

  String.prototype.Trim = function () {

  return this.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 = arguments;

  var str = args[0];

  var re = /{(d+)}/g;

  return str.replace(re, function () { return args[i++] });

  };

  var Json2string = 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 && obj.constructor == Array);

  for (n in obj) {

  v = obj[n]; t = typeof (v);

  if (t == "string") v = " + v + ";

  else if (t == "object" && v !== null)

  v = Json2string(v);

  json.push((arr ? "" : " + n + :") + String(v));

  }

  return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");

  }

  };

【Javascript拓展String方法代碼】相關文章:

javascript跨域訪問的方法07-19

如何調(diào)試javascript腳本呢07-19

數(shù)控編程代碼大全02-13

Java代碼的基本知識09-03

網(wǎng)頁滾動文字的制作HTML代碼04-10

拓展訓練的意義02-04

拓展訓練的歷史起源03-31

拓展訓練的心得感悟02-08

戶外拓展訓練游戲12-07

拓展訓練的標準流程12-07