简体   繁体   English

如何将quoted-printable内容解码为node.js中的普通字符串?

[英]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.

相关问题 解码Ruby / Javascript中的引用可打印字符串 - Decode Quoted-printable strings in Ruby / Javascript 如何在 JavaScript/Node.js 中解码一串组合的 UTF16 和普通字符? - How to decode in JavaScript/Node.js a string of combined UTF16 and normal characters? 如何在javascript(node.js)中将ASCII 7段号解码为普通数 - how to decode ASCII 7 segment number to normal number in javascript (node.js) 如何使用node.js在JSON中向数组添加字符串? - How can I add strings to an array in a JSON using node.js? 如何在node.js中重用WriteStream的内容 - How can I re-use WriteStream's content in node.js 如何使用 node.js 抓取包含动态内容的页面? - How can I scrape pages with dynamic content using node.js? 如何使用StrongLoop在Node.js中提供动态内容? - How can I serve dynamic content in Node.js using StrongLoop? 如何从 Node.js Outlook 加载项中的 Outlook 邮件获取附件内容? - How can I get attachment content from an Outlook mail in a Node.js Outlook add-in? 如何在node.js中正确进行内容编码? - How do I do content encoding properly in node.js? 如何防止使用JS(Node.js)的HTTP查询中允许使用UTF8字符串? - How can I prevent UTF8 strings from being allowed in my HTTP queries using JS (Node.js)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM