VC中用宏实现UNICODE编码转换

来源:互联网 发布:红麦网络舆情监测系统 编辑:程序博客网 时间:2024/06/05 18:18

在 Devstudio6Editor 中添加一下代码,然后在 工具-自定义-宏 中找到 TransUnicode 将它拖到工具栏即可实现汉字的在线转换,方便极了...,对了该方法是同事整的哈。

Sub TransUnicode()
        ' 说明: 将给定字符串转换为UNICODE码。
        Dim win As EnvDTE.Window
        Dim TypeOfFile As Integer
        Dim SrcStr As String
        Dim XStr As String
        Dim DstStr As String
        Dim i, tc As Integer
        Dim ts As String

        win = DTE.ActiveWindow
        If win.Type <> EnvDTE.vsWindowType.vsWindowTypeDocument Then
            MsgBox("This macro can only be run when a text editor window is active.")
        Else
            TypeOfFile = FileType(DTE.ActiveDocument)
            SrcStr = DTE.ActiveDocument.Selection.text()
            XStr = StrConv(SrcStr, vbunicode)
            For i = 0 To XStr.Length - 1
                tc = AscW(XStr.Chars( i ))
                ts = Hex(tc)
                DstStr = DstStr & "/x" & ts
            Next
            DstStr = "L" & """" & DstStr & """" & "/*" & SrcStr & "*/"
            DTE.ActiveDocument.Selection.text() = DstStr
        End If
End Sub

原创粉丝点击