我想在文本中插入“,”我收到的文本如下:A1780G1100001 A1780G1100002 A1780G1100003当我显示文本时,我想这样显示:A1780G1100001,A1780G1100002,A1780G1100003,有哪些方法和代码?
1 回答
呼唤远方
TA贡献1856条经验 获得超11个赞
JS
使用替换功能。
let str='A1780G1100001 A1780G1100002 A1780G1100003';
str = str.replace(/\s+/g, ',');
console.log(str); // "A1780G1100001,A1780G1100002,A1780G1100003"
PHP
使用str_replace或preg_replace
$str = 'A1780G1100001 A1780G1100002 A1780G1100003';
$res = str_replace(' ', ',', $str);
echo $res; // "A1780G1100001,A1780G1100002,A1780G1100003"
echo "\n";
$res = preg_replace('/\s+/', ',', $str);
echo $res; // "A1780G1100001,A1780G1100002,A1780G1100003"
- 1 回答
- 0 关注
- 89 浏览
添加回答
举报
0/150
提交
取消