js 字符串实用方法

<Button type="primary" @click="doIncludes()" style="margin-right: 8px;">验证是否包含</Button>

<Button type="primary" @click="doStartsWith()" style="margin-right: 8px;">验证是否某某开头</Button>

<Button type="primary" @click="doEndsWith()" style="margin-right: 8px;">验证是否某某结尾</Button>

<Button type="primary" @click="doPadStart()" style="margin-right: 8px;">字符串长度补全-前面补足</Button>

<Button type="primary" @click="doPadEnd()" style="margin-right: 8px;">字符串长度补全-结尾补足</Button>

<Button type="primary" @click="doTrimStart()" style="margin-right: 8px;">消除字符串开头空格</Button>

<Button type="primary" @click="doTrimEnd()" style="margin-right: 8px;">消除字符串结尾空格</Button>


doIncludes () {

      if (this.includeStr) {

        alert(this.sourceStr.includes(this.includeStr))

      } else {

        alert(false)

      }

    },

    doStartsWith () {

      if (this.includeStr) {

        alert(this.sourceStr.startsWith(this.includeStr))

      } else {

        alert(false)

      }

    },

    doEndsWith () {

      if (this.includeStr) {

        alert(this.sourceStr.endsWith(this.includeStr))

      } else {

        alert(false)

      }

    },

    doPadStart () {

      alert((this.padStr + '').padStart(2, 0))

    },

    doPadEnd () {

      alert((this.padStr + '').padEnd(2, 0))

    }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。