无法在Javascript和Python中使用替换功能来操作字符串

时间:2019-05-15 08:38:56

标签: javascript python

我以以下方式获取数据:

176019998; 176020000; 176019999; 176020002; 176020001; 176020003;
176019998; 176020000; 176019999; 176020002; 176020001; 176020003;
176019998; 176020000; 176019999; 176020002; 176020001; 176020003;

我想将其更改为

176019998 176020000 176019999 176020002 176020001 176020003 176019998 176020000 176019999 176020002 176020001 176020003 176019998 176020000 176019999 176020002 176020001 176020003

我尝试运行python和javascript代码来执行此操作,而我的代码如下:

Python : 

    x = "176019998; 176020000; 176019999; 176020002; 176020001; 176020003;
    176019998; 176020000; 176019999; 176020002; 176020001; 176020003;
    176019998; 176020000; 176019999; 176020002; 176020001; 176020003;"

    print(x.replace(";"," "))

However, I get the error :

     x = "176019998; 176020000; 176019999; 176020002; 176020001; 176020003;
                                                                             ^
    SyntaxError: EOL while scanning string literal


Javascript :


    let x = "176019998; 176020000; 176019999; 176020002; 176020001; 176020003;
    176019998; 176020000; 176019999; 176020002; 176020001; 176020003;
    176019998; 176020000; 176019999; 176020002; 176020001; 176020003;";

    console.log(x.replace(";"," "));

I get the error : 

    let x = "176019998; 176020000; 176019999; 176020002; 176020001; 176020003;
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    SyntaxError: Invalid or unexpected token
        at new Script (vm.js:79:7)
        at createScript (vm.js:251:10)
        at Object.runInContext (vm.js:284:10)
        at evaluate (/run_dir/repl.js:133:14)
        at ReadStream.<anonymous> (/run_dir/repl.js:116:5)
        at ReadStream.emit (events.js:189:13)
        at addChunk (_stream_readable.js:284:12)
        at readableAddChunk (_stream_readable.js:265:11)
        at ReadStream.Readable.push (_stream_readable.js:220:10)
    at lazyFs.read (internal/fs/streams.js:181:12)


Can you please help me understand, what is wrong with the code.If there a question already about this, please point me in the right direction.

Thanks in advance.

0 个答案:

没有答案