英文:
How to replace the "" in "Hello" with .replace()?
问题
This only replaces the first ", but not the one at the end of a word
partFormatted = partFormatted.replace(""", "");
英文:
This only replaces the first ", but not the one at the end of a word
partFormatted = partFormatted.replace("\"", "");
答案1
得分: 1
使用正则表达式是在其他帖子中没有看到的内容。
具体来说,是全局标志。
partFormatted = partFormatted.replace(/"/g, "");
'g' 表示它应该找到所有给定的匹配项,并用给定的输入替换。
英文:
Something I didn't see in the other post is using a regular expression.
Specifically the global flag.
partFormatted = partFormatted.replace(/"/g, "");
The 'g' indicates it should find all given matches and replace with given input
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论