我想删除字符串周围的“”。
例如,如果字符串是:“I am here”,那么我只想输出I am here。
我想删除字符串周围的“”。
例如,如果字符串是:“I am here”,那么我只想输出I am here。
当前回答
请尝试使用regex从字符串中删除双引号。
$string = "I am here";
$string =~ tr/"//d;
print $string;
exit();
其他回答
请尝试使用regex从字符串中删除双引号。
$string = "I am here";
$string =~ tr/"//d;
print $string;
exit();
这工作…
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));
使用replaceAll
const someStr = 'He said "Hello, my name is Foo"';
console.log(someStr.replaceAll('"', ''));
// => 'He said Hello, my name is Foo'
这个简单的代码也可以工作,例如从双引号包围的字符串中删除双引号:
var str = 'remove "foo" delimiting double quotes';
console.log(str.replace(/"(.+)"/g, '$1'));
如果你想要老派,使用REGEX 1,$s/"//g