Sunny-117 / js-challenges

✨✨✨ Challenge your JavaScript programming limits step by step

Home Page:https://juejin.cn/column/7244788137410560055

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

去除字符串中的字母

Sunny-117 opened this issue · comments

commented
var str = "a2119naskdna";
var newStr = str.replace(/[a-zA-Z]/g, '');//别忘了方括号
console.log(newStr);
let str = "This is a test string with letters.";
let result = "";
for (let i = 0; i < str.length; i++) {
  let char = str.charAt(i);
  if (char < "A" || char > "z" || (char > "Z" && char < "a")) {
    result += char;
  }
}
console.log(result); // "  ."