首页>Program>source

我要在文本中插入","
我收到的文本如下:

A1780G1100001 A1780G1100002 A1780G1100003

当我显示文字时,我想这样显示:

A1780G1100001,A1780G1100002,A1780G1100003,

方法和代码是什么?

最新回答
  • 1月前
    1 #

    JS

    使用替换功能。

    let str='A1780G1100001 A1780G1100002 A1780G1100003';
    str = str.replace(/\s+/g, ',');
    console.log(str); // "A1780G1100001,A1780G1100002,A1780G1100003"
    

    威兹威兹

    使用str_replace或preg_replace

    PHP

    $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"

  • react native:使容器居中,而不使容器内的组件居中RN
  • cordova:升级到wKwebView Ionic 3后,在iOS应用程序中启动后出现白屏