美文网首页
一个简单的移除所有指定字符串的js方法

一个简单的移除所有指定字符串的js方法

作者: Frank_Fang | 来源:发表于2023-07-31 12:02 被阅读0次

首先想到用正则进行replace;
后来想到了一个更简单的方法:

template

<el-table-column v-for="(col, index) in columns" :key="index" :prop="col.prop" :label="col.label">
  <template slot-scope="{row}">
    <span :style="convertSpace(row[col.key])">
      {{ removeSpace(row[col.key]) }}
    </span>
  </template>
</el-table-column>

methods

convertSpace (text) {
  let count = 0
  if (text && text.includes('&nbsp;')) {
    count = [text.split('&nbsp;').length - 1]
  }
  return { paddingLeft: count * 0.5 + 'em' }
},
removeSpace (text) {
  let str = ''
  if (text && text.includes('&nbsp;')) {
    str = text.split('&nbsp;').join('')
  } else {
    str = text
  }
  return str
},

相关文章

  • Python strip()方法

    描述 Python strip() 方法用于移除字符串头尾指定的字符(默认为空格)。 语法 strip()方法语法...

  • Python strip()、split()和rstrip()方

    1. Python strip() 语法描述: Python strip() 方法用于移除字符串头尾指定的字符(默...

  • js在字符串的指定位置插入新的字符

    js在字符串的指定位置插入新的字符 方法一: 方法二:

  • Python strip()方法

    描述 Python strip() 方法用于移除字符串头尾指定的字符(默认为空格)或字符序列。 注意:该方法只能删...

  • Python_去除字符串中的空格

    作者:Gakki 01. strip() 方法 strip() :用于移除字符串头尾指定的字符(默认为空格)或字符...

  • strip()方法

    Python strip() 方法用于移除字符串头尾指定的字符(默认为空格)或字符序列。 注意:该方法只能删除开头...

  • 字符串的 strip()方法 2018-10-04

    描述 字符串的 strip([chars])方法用来移除字符串头尾指定的字符(默认为空格或者换行符)或字符序列 参...

  • 方法速记

    1: .strip()方法用于移除字符串头尾指定的字符(默认为空格),返回值为str。 .lstrip(...

  • 如何删除节点

    移除指定元素方法 empty()方法 清空元素中的所有后代节点 不能删除自己本身这个节点 remove()方法 该...

  • Day4-作业

    '''表中所有字符串相关方法的使用方式都是: 字符串.方法名()字符串.capitalize() ---将指定的...

网友评论

      本文标题:一个简单的移除所有指定字符串的js方法

      本文链接:https://www.haomeiwen.com/subject/jbyepdtx.html