Converting the chrw function to Chinese Characters in VB. NET

Source: Internet
Author: User
Tags reflector
'If reflector is used and the program contains Chinese characters, the reflector will be represented in code. If it is converted to C #, there are many solutions on the Internet, but VB.net cannot find them. 'vb. NET may be more complex. After all, C # is still a complete string, while VB is split into one word, and then the following code in & concatenate solves this problem, copy it to the macro editor and save it. 'It's silly to write it, so it's easy to optimize it. :) imports system
Imports envdte
Imports envdte80
Imports system. Diagnostics
Imports system. Text. regularexpressionspublic module unicode2character
'You must manually select a single word
Public sub single-word conversion ()
Dim doc as document = DTE. activedocument
Dim doctext as textdocument = Doc. Object
Dim seltext as textselection = doctext. Selection ()
Dim text as string = seltext. Text
Dim ch as char = Cc (text)
Doctext. replacepattern (text, CH)
End sub 'replace all Chinese characters in the current file
Public sub all conversions ()
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 text. regularexpressions. match first find the "string": chrw (12345) & chrw (23456)... & chrw (56789)
Dim strpattern as string = "(chrw \ ([0-9] {5} \) \ s & \ s) + chrw \ ([0-9] {5 }\)"
M = RegEx. Match (text, strpattern, regexoptions. ignorecase)
If M. Success then
Dim strmatch as string = M. Value
Dim strvalue as string = M. Value
TEXT = text. Replace (strvalue ,"")
Strvalue = strvalue. Replace ("&","")
Strvalue = strvalue. Replace ("","")
Strvalue = strvalue. Replace ("chrw (","")
Strvalue = strvalue. Replace (")", "") dim chars as integer = strvalue. Length ()
Chars = chars \ 5
Dim strnew as string = ""
For I as integer = 0 to chars-1
Dim X as string = strvalue. substring (I * 5, 5)
Strnew = strnew & IC (X)
Next
Doctext. replacepattern (strmatch, "& strnew &"""")
Else
Exit do
End if
If not text. Length <ilength then
Exit do
End if
Loop seltext. selectall ()
TEXT = seltext. Text
Do
Ilength = text. Length
Dim M as text. regularexpressions. Match find another word: "& chrw (23456 )&"
Dim strpattern as string = "\" "\ s & \ schrw \ ([0-9] {5} \) \ s & \ s \"""
M = RegEx. Match (text, strpattern, regexoptions. ignorecase)
If M. Success then
Dim strmatch as string = M. Value
Dim strvalue as string = M. Value
TEXT = text. Replace (strvalue ,"")
Strvalue = strvalue. Replace ("&","")
Strvalue = strvalue. Replace ("","")
Strvalue = strvalue. Replace ("chrw (","")
Strvalue = strvalue. Replace (")","")
Strvalue = strvalue. Replace ("""","")
Dim strnew = IC (strvalue)
Doctext. replacepattern (strmatch, strnew)
Else
Exit do
End if
If not text. Length <ilength then
Exit do
End if
Loop seltext. selectall ()
TEXT = seltext. Text
Do
Ilength = text. Length
Dim M as text. regularexpressions. Match find another word: "& chrw (23456)
Dim strpattern as string = "\" "\ s & \ schrw \ ([0-9] {5 }\)"
M = RegEx. Match (text, strpattern, regexoptions. ignorecase)
If M. Success then
Dim strmatch as string = M. Value
Dim strvalue as string = M. Value
TEXT = text. Replace (strvalue ,"")
Strvalue = strvalue. Replace ("&","")
Strvalue = strvalue. Replace ("","")
Strvalue = strvalue. Replace ("chrw (","")
Strvalue = strvalue. Replace (")","")
Strvalue = strvalue. Replace ("""","")
Dim strnew = IC (strvalue)
Doctext. replacepattern (strmatch, strnew &"""")
Else
Exit do
End if
If not text. Length <ilength then
Exit do
End if
Loop seltext. selectall ()
TEXT = seltext. Text
Do
Ilength = text. Length
Dim M as text. regularexpressions. Match find another word: chrw (23456 )&"
Dim strpattern as string = "chrw \ ([0-9] {5} \) \ s & \ s \"""
M = RegEx. Match (text, strpattern, regexoptions. ignorecase)
If M. Success then
Dim strmatch as string = M. Value
Dim strvalue as string = M. Value
TEXT = text. Replace (strvalue ,"")
Strvalue = strvalue. Replace ("&","")
Strvalue = strvalue. Replace ("","")
Strvalue = strvalue. Replace ("chrw (","")
Strvalue = strvalue. Replace (")","")
Strvalue = strvalue. Replace ("""","")
Dim strnew = IC (strvalue)
Doctext. replacepattern (strmatch, "& strnew)
Else
Exit do
End if
If not text. Length <ilength then
Exit do
End if
Loop seltext. selectall ()
TEXT = seltext. Text
Do
Ilength = text. Length
Dim M as text. regularexpressions. Match 'last word: chrw (23456)
Dim strpattern as string = "chrw \ ([0-9] {5 }\)"
M = RegEx. Match (text, strpattern, regexoptions. ignorecase)
If M. Success then
Dim strmatch as string = M. Value
Dim strvalue as string = M. Value
TEXT = text. Replace (strvalue ,"")
Strvalue = strvalue. Replace ("","")
Strvalue = strvalue. Replace ("chrw (","")
Strvalue = strvalue. Replace (")","")
Dim strnew = IC (strvalue)
Doctext. replacepattern (strmatch, "& strnew &"""")
Else
Exit do
End if
If not text. Length <ilength then
Exit do
End if
Loop end sub
Private function CC (byval STR as string) as char
Dim int as integer = CINT (Str. substring (5, 5 ))
Dim ch as char = chrw (INT)
Return ch
End Function
Private function IC (byval int as integer) as char
Dim ch as char = chrw (INT)
Return ch
End functionend Module

Appendix:
Charcode value and character conversion are supported.
Http://www.geocities.com/george_ruban/charset/CharCode.html

Hope to help you

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.