
在 Google Sheets(Google Drive/Google Docs)中,是否有一个官方函数可以将文本转义为 XML 中的值?
例如
Mytext<hello
输出应类似
Mytext<hello
如果没有,是否有最佳实践的正则表达式替换?
答案1
我写了一个自定义函数:
function xmlescape(text) {
return text.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
我希望我没有忘记什么。