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

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


当前回答

str = str.replace(/^"(.*)"$/, '$1');

只有当引号是字符串的第一个和最后一个字符时,这个regexp才会删除引号。F.ex:

"I am here"  => I am here (replaced)
I "am" here  => I "am" here (untouched)
I am here"   => I am here" (untouched)

其他回答

str = str.replace(/^"(.*)"$/, '$1');

只有当引号是字符串的第一个和最后一个字符时,这个regexp才会删除引号。F.ex:

"I am here"  => I am here (replaced)
I "am" here  => I "am" here (untouched)
I am here"   => I am here" (untouched)
var expressionWithoutQuotes = '';
for(var i =0; i<length;i++){
    if(expressionDiv.charAt(i) != '"'){
        expressionWithoutQuotes += expressionDiv.charAt(i);
    }
}

这可能对你有用。

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

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

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

$(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 Stringstr = "\"I am here\"";
  var mystring = String(Stringstr);
  mystring = mystring.substring(1, mystring.length - 1);
  alert(mystring);