如何转换引用可打印字符串 [英] How to convert Quoted-Print String

查看:155
本文介绍了如何转换引用可打印字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的法国字符串在.NET
解码的邮件内容,我收到Chasn = C3 = A9河畔illet
我想获得伊莱河畔沙斯内
和我没有找到任何解决方案断言2天网络搜索。

I'm working on French String in .NET Decoding a Mail body , I receive "Chasn=C3=A9 sur illet" I would like to get "Chasné sur illet" and i don't find any solution aver 2 days web search.

C#OU VB.NET
任何人都可以帮助我吗?

C# ou VB.NET Can anyone helps me ?

感谢

推荐答案

这是UTF8编码。

使用这个帖子:

http://www.dpit.co.uk/decoding-quoted-printable-email-in-c/

下面是代码(不要忘了接受的答案,如果帮助):

Here is the code (don't forget to accept the answer if helped):

using System;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine(DecodeQuotedPrintable("Chasn=C3=A9 sur illet"));
            Console.ReadKey();
        }

        static string DecodeQuotedPrintable(string input)
        {
            var occurences = new Regex(@"(=[0-9A-Z][0-9A-Z])+", RegexOptions.Multiline);
            var matches = occurences.Matches(input);
            foreach (Match m in matches)
            {
                byte[] bytes = new byte[m.Value.Length / 3];
                for (int i = 0; i < bytes.Length; i++)
                {
                    string hex = m.Value.Substring(i * 3 + 1, 2);
                    int iHex = Convert.ToInt32(hex, 16);
                    bytes[i] = Convert.ToByte(iHex);
                }
                input = input.Replace(m.Value, Encoding.UTF8.GetString(bytes));
            }
            return input.Replace("=rn", "");
        }
    }
}

这篇关于如何转换引用可打印字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆