2017-05-07 99 views
0

我想在字符串中使用javascript ecma6中的模板文字中的字符串。是否可以将双引号或单引号添加到字符串中的tamplate litaral输出。 我使用路径字符串中的目录输出作为字符串来解决此问题。字符串中的字符串与模板文字

let input = "C:\users\document" 

我想child.stdin.write('athom project --run "C:\users\document" \n')

我来到这个child.stdin.write('athom project --run "' + $ {}输入+ '"C:\users\document \n')

心不是有没有更合适的方法来做到这一点在ecma6?

回答

4

A template literal由反引号(`)分隔。您目前正试图用单引号分隔它。

这样做:

let input = "C:\users\document"; 
child.stdin.write(`athom project --run "${input}"\n`); 
+1

我写这样的:我来这child.stdin.write( 'athom项目--run“' +'$ {}输入'+'“C:\用户\文件\ n')。代码编辑器删除了$ {input}后面的图片。仍然如此。你给的答案是我正在寻找的。 – wetlip