gpt4 book ai didi

javascript - JavaScript 中的字符串替换无法正常工作

转载 作者:行者123 更新时间:2023-11-30 12:04:48 25 4
gpt4 key购买 nike

<?php
$str = "this is a . test . string.";
?>

<script>
var str = '<?php echo $str; ?>';
wordss = ' . ';
var res = str.replace(new RegExp(wordss,"g"),". "); //space(.)space convert to (.)space
console.log(res);
</script>

输出

this is. . test. string.

我想要它在“这是一个.test.string.

最佳答案

var str = "this is a . test . string.";
var res = str.split(" . ").join(". ");
console.log(res);

关于javascript - JavaScript 中的字符串替换无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35556466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com