这是我的代码。它应该将文本翻译成二进制文件并返回。它告诉我单词响应没有定义,函数asktocode和asktodecode也没有。帮助将不胜感激。 (: 这很棒。我甚至包括了按钮的想法,使其更加用户友好。 谢谢。 路加福音 它希望我添加更多单词,所以我想我必须这样做。
function texttobin(code) {
var A = 01000001
var B = 01000010
var C = 01000011
var D = 01000100
var E = 01000101
var F = 01000110
var G = 01000111
var H = 01001000
var I = 01001001
var J = 01001010
var K = 01001011
var L = 01001100
var M = 01001101
var N = 01001110
var O = 01001111
var P = 01010000
var Q = 01010001
var R = 01010010
var S = 01010011
var T = 01010100
var U = 01010101
var V = 01010110
var W = 01010111
var X = 01011000
var Y = 01011001
var Z = 01011010
var a = 01100001
var b = 01100010
var c = 01100011
var d = 01100100
var e = 01100101
var f = 01100110
var g = 01100111
var h = 01101000
var i = 01101001
var j = 01101010
var k = 01101011
var l = 01101100
var m = 01101101
var n = 01101110
var o = 01101111
var p = 01110000
var q = 01110001
var r = 01110010
var s = 01110011
var t = 01110100
var u = 01110101
var v = 01110110
var w = 01110111
var x = 01111000
var y = 01111001
var z = 01111010
var comma = 00101110
var period = 00110010
var one = 00110011
var two = 00110101
var three = 00110111
var four = 00111000
var five = 00111001
var six = 00110000
var seven = 00110111
var eight = 00111000
var nine = 00111001
var zero = 00110000
var spacebar = 00100000
var asktocode; "Translate text into binary"
// Display a dialog box with a message and "Yes" and "No" buttons.
var ui = DocumentApp.getUi();
var response = ui.alert('Are you sure you want to continue?', ui.ButtonSet.YES_NO);
// Process the user's response.
if (response == ui.Button.YES) {
Logger.log('The user clicked "Yes."');
} else {
Logger.log('The user clicked "No" or the dialog\'s close button.');
}
function bintotext (translate) {
var asktodecode; "Translate binary into text"
}
}
答案 0 :(得分:0)
我真的不明白你在哪里使用该代码,但将文本转换为二进制和返回非常简单:
var text = "A";
// character to binary (result: "1000001")
var bin = text.charCodeAt(0).toString(2);
// binary back to character (result: "A")
var char = String.fromCharCode(parseInt(bin, 2));