How to convert Quoted-Print String

后端 未结 5 400
执笔经年
执笔经年 2021-01-14 22:18

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 ave

5条回答
  •  猫巷女王i
    2021-01-14 22:45

        static string ConverFromHex(string source)
        {
            string target = string.Empty;
    
            int startPos = source.IndexOf('=', 0);
            int prevStartPos = 0;
            while (startPos >= 0)
            {
                // concat with substring from source
                target += source.Substring(prevStartPos, startPos - prevStartPos);
    
                // next offset
                startPos++;
    
                // update prev pos
                prevStartPos = startPos;
    
                // get substring
                string hexString = source.Substring(startPos, 2);
    
                // get int equiv
                int hexNum = 0;
                if (int.TryParse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier, System.Globalization.CultureInfo.InvariantCulture, out hexNum))
                {
                    // add to target string
                    target += (char)hexNum;
    
                    // add hex length
                    prevStartPos += 2;
                }
    
                // next occurence
                startPos = source.IndexOf('=', startPos);
            }
    
            // add rest of source
            target += source.Substring(prevStartPos);
    
            return target;
        }
    

提交回复
热议问题