Skip to content

支持任意 JavaScript 环境或框架

去掉字符串空格

removeLeftSpace

去掉字符串左边空格

查看代码
vue
<script setup lang="ts">
import { ref, computed } from "vue";
import { removeLeftSpace } from "@pureadmin/utils";

let str = ref(" i love study ");
let code = computed(() => {
  return `console.log(${str.value})`;
});
</script>

<template>
  <naive-theme>
    <n-space className="flex items-center mt-2">
      原字符串:
      <n-code
        :code="`console.log( i love study )`"
        language="javascript"
        inline
      />
    </n-space>

    <n-space className="flex items-center mt-2">
      转换后字符串:
      <n-code :code="code" language="javascript" inline />
    </n-space>

    <n-space className="flex items-center mt-2">
      <n-button @click="str = removeLeftSpace(' i love study ')">
        点击去掉字符串左边空格
      </n-button>
    </n-space>
  </naive-theme>
</template>

接收一个参数 str ,返回值类型 string

参数属性说明类型
str字符串string

removeRightSpace

去掉字符串右边空格

查看代码
vue
<script setup lang="ts">
import { ref, computed } from "vue";
import { removeRightSpace } from "@pureadmin/utils";

let str = ref(" i love study ");
let code = computed(() => {
  return `console.log(${str.value})`;
});
</script>

<template>
  <naive-theme>
    <n-space className="flex items-center mt-2">
      原字符串:
      <n-code
        :code="`console.log( i love study )`"
        language="javascript"
        inline
      />
    </n-space>

    <n-space className="flex items-center mt-2">
      转换后字符串:
      <n-code :code="code" language="javascript" inline />
    </n-space>

    <n-space className="flex items-center mt-2">
      <n-button @click="str = removeRightSpace(' i love study ')">
        点击去掉字符串右边空格
      </n-button>
    </n-space>
  </naive-theme>
</template>

接收一个参数 str ,返回值类型 string

参数属性说明类型
str字符串string

removeBothSidesSpace

去掉字符串左右两边空格

查看代码
vue
<script setup lang="ts">
import { ref, computed } from "vue";
import { removeBothSidesSpace } from "@pureadmin/utils";

let str = ref(" i love study ");
let code = computed(() => {
  return `console.log(${str.value})`;
});
</script>

<template>
  <naive-theme>
    <n-space className="flex items-center mt-2">
      原字符串:
      <n-code
        :code="`console.log( i love study )`"
        language="javascript"
        inline
      />
    </n-space>

    <n-space className="flex items-center mt-2">
      转换后字符串:
      <n-code :code="code" language="javascript" inline />
    </n-space>

    <n-space className="flex items-center mt-2">
      <n-button @click="str = removeBothSidesSpace(' i love study ')">
        点击去掉字符串左右两边空格
      </n-button>
    </n-space>
  </naive-theme>
</template>

接收一个参数 str ,返回值类型 string

参数属性说明类型
str字符串string

removeAllSpace

去掉字符串全部空格

查看代码
vue
<script setup lang="ts">
import { ref, computed } from "vue";
import { removeAllSpace } from "@pureadmin/utils";

let str = ref(" i love study ");
let code = computed(() => {
  return `console.log(${str.value})`;
});
</script>

<template>
  <naive-theme>
    <n-space className="flex items-center mt-2">
      原字符串:
      <n-code
        :code="`console.log( i love study )`"
        language="javascript"
        inline
      />
    </n-space>

    <n-space className="flex items-center mt-2">
      转换后字符串:
      <n-code :code="code" language="javascript" inline />
    </n-space>

    <n-space className="flex items-center mt-2">
      <n-button @click="str = removeAllSpace(' i love study ')">
        点击去掉字符串全部空格
      </n-button>
    </n-space>
  </naive-theme>
</template>

接收一个参数 str ,返回值类型 string

参数属性说明类型
str字符串string

Released under the MIT License