Imports System.Text.RegularExpressions
------------------------------------------
Sub Unicode2Character()
        Dim doc As Document = DTE.ActiveDocument
        Dim docText As TextDocument = doc.Object
        Dim selText As TextSelection = docText.Selection()
        selText.SelectAll()
        Dim text As String = selText.Text
        Dim iLength As Integer
        Do
            iLength = text.Length
            Dim m As Match
            Dim strPattern As String = "(?<code>\\u[A-F0-9]{4})"
            m = Regex.Match(text, strPattern, RegexOptions.IgnoreCase)
            If m.Success Then
                Dim strValue As String
                strValue = m.Groups("code").Value
                text = text.Replace(strValue, "")
                Dim int As Integer
                int = System.Int32.Parse(strValue.Substring(2, 4), NumberStyles.HexNumber)
                Dim ch As Char = ChrW(int)
                docText.ReplacePattern(strValue, ch)
            Else
                Exit Do
            End If
            If Not text.Length < iLength Then
                Exit Do
            End If
        Loop
        selText.StartOfDocument()
    End Sub

解决方案 »

  1.   

    http://www.developerfusion.com/utilities/convertvbtocsharp.aspx
    到上面这个网试试
      

  2.   

    楼上的网站真的不错;using System.Text.RegularExpressions;
    void Unicode2Character() 

     Document doc = DTE.ActiveDocument; 
     TextDocument docText = doc.Object; 
     TextSelection selText = docText.Selection(); 
     selText.SelectAll(); 
     string text = selText.Text; 
     int iLength; 
     do { 
       iLength = text.Length; 
       Match m; 
       string strPattern = "(?<code>\\\\u[A-F0-9]{4})"; 
       m = Regex.Match(text, strPattern, RegexOptions.IgnoreCase); 
       if (m.Success) { 
         string strValue; 
         strValue = m.Groups("code").Value; 
         text = text.Replace(strValue, ""); 
         int int; 
         int = System.Int32.Parse(strValue.Substring(2, 4), NumberStyles.HexNumber); 
         char ch = ChrW(int); 
         docText.ReplacePattern(strValue, ch); 
       } else { 
         goto exitDoLoopStatement0; 
       } 
       if (!(text.Length < iLength)) { 
         goto exitDoLoopStatement1; 
       } 
     } while (true); 
     exitDoLoopStatement1: ; 
     selText.StartOfDocument(); 
    }
      

  3.   

    goto exitDoLoopStatement1; 
    这个在C#是退出循环的意思吗?我刚学C#
      

  4.   

    using System.Text.RegularExpressionsvoid Unicode2Character()
    {
         Document doc = DTE.ActiveDocument;
         TextDocument docText = doc.Object;
         TextSelection selText = docText.Selection();
         selText.SelectAll();
         string text = selText.Text;
         int iLength;
         while(true)
         {  
             iLength = text.Length;
             Match m;
             string strPattern = @"(?<code>\\u[A-F0-9]{4})";
             m = Regex.Match(text, strPattern, RegexOptions.IgnoreCase);
             if(m.Success)
             {
                string strValue = m.Groups["code"].Value;
                text = text.Replace(strValue, "");
                int intt = System.Int32.Parse(strValue.Substring(2, 4), NumberStyles.HexNumber);
                char ch = (char)intt;
                docText.ReplacePattern(strValue, ch);
             }
             else
                 break;
             if(!(text.Length < iLength))
                 break;
         }
         selText.StartOfDocument();
    }
      

  5.   

    using System.Text.RegularExpressionsprivate void Unicode2Character()
    {
            Document doc = DTE.ActiveDocument;
            TextDocument docText = doc.Object;
            TextSelection selText = docText.Selection();
            selText.SelectAll();
            string text = selText.Text;
            int iLength;
            while(true)
            {
                iLength = text.Length;
                Match m;
                string strPattern = "(?<code>\\u[A-F0-9]{4})";
                m = Regex.Match(text, strPattern, RegexOptions.IgnoreCase);
                if(m.Success)
                {
                    string strValue;
                    strValue = m.Groups("code").Value;
                    text = text.Replace(strValue, "");
                    int int1;
                    int1 = System.Int32.Parse(strValue.Substring(2, 4), NumberStyles.HexNumber);
                    char ch = (char)int1;
                    docText.ReplacePattern(strValue, ch);
                }
                else
                    break;
                if(! text.Length < iLength)
                    break;
            }
            selText.StartOfDocument();
    }其中用到的对象要自己添加引用
      

  6.   

    这个是一个使用正则表达试的函数。
    我只要输出个函数就行了。
    Function Unicode2Character(String):String;//替换\u1234到汉字
    Begin
    end;