[英]How can I decode quoted-printable content to normal strings in node.js?
For example, I have a string "this=20is=20a=20string" that I want to convert to "this is a string". 例如,我有一个字符串“this = 20is = 20a = 20string”,我想将其转换为“这是一个字符串”。
Is there a library function or a npm module that does it or should I make my own function to do it? 是否有库函数或npm模块可以执行此操作,还是应该创建自己的函数?
Use mimelib: 使用mimelib:
var mimelib = require("mimelib");
mimelib.decodeQuotedPrintable("this=20is=20a=20string") === "this is a string"
mimelib.decodeMimeWord("=?iso-8859-1?Q?=27text=27?=") === "'text'"
s = "this=20is=20a=20string"
s.replace(/=20/g, ' '); // => "this is a string"
Although if =20
is meant to be a hex character number (delimited by "=" instead of "%"?) then this would be more general: 虽然if
=20
是十六进制字符数(由“=”而不是“%”分隔?),但这更通用:
"foo=21".replace(/=([A-Fa-f0-9]{2})/g, function(m, g1) {
return String.fromCharCode(parseInt(g1, 16));
}); // => "foo!"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.