【问题标题】:window.btoa( // here programcode // ) how to do that?window.btoa( // 这里是程序代码 // ) 怎么做?
【发布时间】:2016-03-12 15:15:50
【问题描述】:

我的目标是用 window.btoa() 对我的 programmcode 进行编码,但是我如何编写一个带有 programmcode 的字符串 - 问题是编译器认为该字符串在代码中的第一个 " 之后结束。

示例:

var engine = '';


function all_this_in_the_string() {
  var examples_string = 'single';
  var double_ = "double";
}

// I have about 600 lines code with single and double quotes...of course the code is in more than one line.
// Is there a way to get this code into the string (engine) that i can encode with the line above ?

console.log(window.btoa(engine));

问候, 大卫

【问题讨论】:

  • 然后正确引用代码
  • 转义引号?
  • @FelixKling 我编辑了我的问题,这不是我搜索的内容 - 感谢您的说明。 :)
  • @FelixKling 并删除标记为重复的-.-
  • 也许您正在寻找all_this_in_string.toString()?还真说不出来。请将您的问题的标题更新为描述性的内容。我还建议阅读 How to Ask 以了解如何提出更好的问题。

标签: javascript window encode


【解决方案1】:

您需要在单引号和双引号之间变化。

var engine = 'function() { var examples_string = "here_is_the_problem"}';

【讨论】:

  • 你也可以转义引号'function() { var examples_string = \'here_is_the_problem\'}'
猜你喜欢
  • 2020-05-24
  • 1970-01-01
  • 2012-01-08
  • 2018-06-20
  • 2022-07-18
  • 2022-06-11
  • 2020-04-21
  • 2021-11-08
  • 1970-01-01
相关资源
最近更新 更多