示例#1
0
        private void MessageReceived(EventWithPater obj)
        {
            if (obj.ModuleInfo.ModuleType != typeof(EncodeModule).AssemblyQualifiedName)
            {
                if (string.IsNullOrEmpty(obj._msg))
                {
                    return;
                }

                Message = string.Empty;
                // Define a test string.
                var msg = obj._msg;
                //string text = "The the quick 人 fox 狐狸 jumps over the lazy 狗狗.";
                Regex rx = new Regex(@"[^\u0000-\u00FF]", RegexOptions.Compiled | RegexOptions.IgnoreCase);

                // Find matches.
                MatchCollection matches = rx.Matches(msg);
                foreach (Match match in matches)
                {
                    GroupCollection groups = match.Groups;
                    var             bytes  = Encoding.Unicode.GetBytes(groups[0].Value);
                    var             temp   = $"\\u{string.Format("{0:x2}", bytes[1])}{string.Format("{0:x2}", bytes[0])}";
                    msg = rx.Replace(msg, temp, 1);
                }

                Message += msg;
            }
        }
示例#2
0
 private void MessageReceived(EventWithPater obj)
 {
     if (obj.ModuleInfo.ModuleType != typeof(DecodeModule).AssemblyQualifiedName)
     {
         if (string.IsNullOrEmpty(obj._msg))
         {
             return;
         }
         Message = string.Empty;
         var msg = Regex.Unescape(obj._msg);
         //msg = Helper.Unicode2String(obj._msg);
         //msg = HttpUtility.UrlDecode(obj._msg.Replace(@"\u", @"%u").Replace(@";", ""));
         Message += msg;
     }
 }