String.js
上传用户:ahit0551
上传日期:2009-04-15
资源大小:2345k
文件大小:1k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /**
  2.  * <p>Title: 扩展String</p>
  3.  * <p>Description: </p>
  4.  * <p>Copyright: Copyright (c) xio.name 2006</p>
  5.  * @author xio
  6.  */
  7. String.prototype.contains = function (A) {
  8.     return (this.indexOf(A) > -1);
  9. };
  10. String.prototype.equals = function () {
  11.     for (var i = 0; i < arguments.length; i++) {
  12.         if (this == arguments[i]) {
  13.             return true;
  14.         }
  15.     }
  16.     return false;
  17. };
  18. String.prototype.startsWith = function (A) {
  19.     return (this.substr(0, A.length) == A);
  20. };
  21. String.prototype.endsWith = function (A, B) {
  22.     var C = this.length;
  23.     var D = A.length;
  24.     if (D > C) {
  25.         return false;
  26.     }
  27.     if (B) {
  28.         var E = new RegExp(A + "$", "i");
  29.         return E.test(this);
  30.     } else {
  31.         return (D == 0 || this.substr(C - D, D) == A);
  32.     }
  33. };
  34. String.prototype.remove = function (A, B) {
  35.     var s = "";
  36.     if (A > 0) {
  37.         s = this.substring(0, A);
  38.     }
  39.     if (A + B < this.length) {
  40.         s += this.substring(A + B, this.length);
  41.     }
  42.     return s;
  43. };
  44. String.prototype.trim = function () {
  45.     return this.replace(/(^s*)|(s*$)/g, "");
  46. };
  47. String.prototype.ltrim = function () {
  48.     return this.replace(/^s*/g, "");
  49. };
  50. String.prototype.rtrim = function () {
  51.     return this.replace(/s*$/g, "");
  52. };
  53. String.prototype.replaceNewLineChars = function (A) {
  54.     return this.replace(/n/g, A);
  55. };