去除字符串中的字母
Sunny-117 opened this issue · comments
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); // " ."