繁体   English   中英

我正在尝试编写一个函数来简化字符串内的字符串连接。 例如'“abc”+“defg”'变成'“abcdefg”'

[英]I'm trying to write a function to simplify string concatenations inside an string. e.g. ' “abc” + “defg” ' turns into ' “abcdefg” '

很难解释,但我需要一个函数来做这样的事情:

  1. 输入: cleanStr(" console.log('abc' + 'defg') ")

    输出: "console.log('abcdefg')"

  2. 输入: cleanStr(" console.log(['abc' + \\"123\\", 'other', 'other']) ")

    输出: "console.log(['abc123', 'other', 'other'])"

  3. 输入: cleanStr(" console.log({ "key": \\"abc\\" + 'def', "other": ('hello ') + 'world' }) ")

    输出: "console.log({ "key": \\"abcdef\\", "other": 'hello world' })"

我所有的尝试在其中一些测试中都失败了 /\\

尝试运行" ['abc' + 'defg', 'abc', 'abc'] " ,输出将正是我希望我的函数返回的内容,但在字符串上。

规则:

  • 需要使用"'
  • 需要使用()例如('string') + 'string'
  • 只加入' + '而不是', '
  • 不能使用eval

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM