我想删除字符串周围的“”。

例如,如果字符串是:“I am here”,那么我只想输出I am here。


当前回答

如果要删除字符串中的所有双引号,请使用

var str = '"some "quoted" string"';
console.log( str.replace(/"/g, '') );
// some quoted string

否则,你想要删除字符串周围的引号,使用:

var str = '"some "quoted" string"';
console.log( clean = str.replace(/^"|"$/g, '') );
// some "quoted" string

其他回答

这工作…

var string1 = "'foo'"; var string2 = '"bar"'; function removeFirstAndLastQuotes(str){ var firstChar = str.charAt(0); var lastChar = str[str.length -1]; //double quotes if(firstChar && lastChar === String.fromCharCode(34)){ str = str.slice(1, -1); } //single quotes if(firstChar && lastChar === String.fromCharCode(39)){ str = str.slice(1, -1); } return str; } console.log(removeFirstAndLastQuotes(string1)); console.log(removeFirstAndLastQuotes(string2));

这段代码是非常好的显示数字在文本框

$(this) =[你的文本框]

            var number = $(this).val();
            number = number.replace(/[',]+/g, '');
            number = number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
            $(this).val(number); // "1,234,567,890"

如果要删除字符串中的所有双引号,请使用

var str = '"some "quoted" string"';
console.log( str.replace(/"/g, '') );
// some quoted string

否则,你想要删除字符串周围的引号,使用:

var str = '"some "quoted" string"';
console.log( clean = str.replace(/^"|"$/g, '') );
// some "quoted" string

使用replaceAll

const someStr = 'He said "Hello, my name is Foo"';

console.log(someStr.replaceAll('"', '')); 

// => 'He said Hello, my name is Foo'

请尝试使用regex从字符串中删除双引号。

    $string = "I am here";
    $string =~ tr/"//d;
    print $string;
    exit();