以下示例是关于Javascript中包含将普通文本转换为代码并在需要时检索用法的示例代码,想了解将普通文本转换为代码并在需要时检索的具体用法?将普通文本转换为代码并在需要时检索怎么用?将普通文本转换为代码并在需要时检索使用的例子?那么可以参考以下相关示例代码来学习它的具体使用方法。
function stringToCode(str) {
let unicode = ''
let arr = str.split('').forEach( (char, index) => {
unicode += str.charCodeAt(index) + ' '
})
return unicode.trim()
}
function codeToString(code) {
let mainText = ''
let textArr = code.split(' ').forEach( value => {
mainText += String.fromCharCode(value)
})
return mainText
}
let text = `In human language, this means: If myName has no value, run setUserName() again from the start. If it does have a value (if the above statement is not true), then store the value in localStorage and set it as the heading's text.`
let code = stringToCode(text)
codeToString(code)
本文地址:https://www.itbaoku.cn/snippets/789798.html