During product development, you know that i18n is required. But in development Code In the process, because you need to first focus on the logic implementation, so the file will inevitably hardcode Chinese text or something. After the UI description and business logic of the Code are stable, you need to check whether there are any Chinese Resources in the Code. For descriptions similar to error prompts Program When no error is found, tester cannot be found.
However, if this check depends on the eyes, it is also very depressing. In addition to writing additional tool analysis documents, is there any other simple and automatic way to help us solve the problem? Vs. NET 2003 provides me with very powerful macro functions (you can use the. NET Framework class library in macros !), Therefore, it is too appropriate to use macros to solve such small cases. The following macro function is to find non-ASCII characters in the current document and output the row number and content to the output tool window. The Code is as follows: Imports Envdte
Imports System. Windows. Forms
Imports System. Text
Imports System. Globalization
Imports System. Text. regularexpressions
Imports System. Diagnostics
Imports Mymacros. util
Public Module birdshome Module Birdshome
Sub findchinesewords () Sub Findchinesewords ()
Dim Doc As Document = DTE. activedocument
Dim Doctext As Textdocument = Doc. Object
Dim Linecount = Doctext. endpoint. Line
Dim EP As Editpoint = Doctext. startpoint. createeditpoint ()
Dim Strline As String
Dim I As Integer
Dim RegEx As RegEx = New RegEx ( " [^ \ U0000-\ u00ff] + " )
Dim Strbresult As Stringbuilder = New Stringbuilder
For I = 1 To Linecount - 1
Strline = Ep. getlines (I, I + 1 )
Dim M As Matchcollection = RegEx. Matches (strline)
If M. Count > 0 Then
Strbresult. append (I. tostring ())
Strbresult. append ( " . " )
Dim J As Integer
For J = 0 To M. Count - 1
Strbresult. append (M (j). value)
Strbresult. append ( " , " )
Next
Strbresult. Length = Strbresult. Length - 2
Strbresult. append ( " ; " )
Strbresult. append (system. environment. newline)
End If
Next
' MessageBox. Show (strbresult. tostring)
Dim Win As Window = DTE. Windows. Item (constants. vswindowkindcommandwindow)
Dim Target As Object
If (DTE. activewindow Is Win) Then
Target = Win. Object
Else
Target = Getoutputwindowpane ( " Chinese Words " )
Target. Clear ()
End If
Target. outputstring (strbresult. tostring ())
End sub
End Module
The getoutputwindowpane method is in the following public module:
Imports Envdte
Imports System. Diagnostics
Public Module util Module Util
Function getoutputwindowpane () Function Getoutputwindowpane ( Byval Name As String , Optional Byval Show As Boolean = True ) As Outputwindowpane
Dim Win As Window = DTE. Windows. Item (envdte. constants. vswindowkindoutput)
If Show Then Win. Visible = True
Dim Ow As Outputwindow = Win. Object
Dim Owpane As Outputwindowpane
Try
Owpane = Ow. outputwindowpanes. Item (name)
Catch E As System. Exception
Owpane = Ow. outputwindowpanes. Add (name)
End Try
Owpane. Activate ()
Return Owpane
End Function
End Module
// Write more VB and think its syntax is quite natural :)
Take the HTML code (formatted by IDE) on the Chinese Google homepage as an example. The result of running this script code is as follows: