VB.NET开发环境的出现,帮助开发人员实现了许多特定的功能需求。比如在对移动设备的操作方面等。VB.NET汉字转换中若使用Reflector,而且程序中有中文字符,Reflector会用代码表示。若反成C#,网上有很多解决方案了,而VB.NET却找不到。VB.NET里可能更复杂些,毕竟C#还是一个完整的字符串,而VB中却被拆成一个一个单字,然后用&连接。#t#

10年积累的网站建设、成都网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先做网站后付款的网站建设流程,更有凌河免费网站建设让你可以放心的选择与我们合作。
下面这段VB.NET汉字转换代码解决了这个问题,将其拷到宏编辑器里保存即可,写的有点傻傻的,懒得优化了,好使就行:)
- '全部替换当前文件的汉字
 - Public Sub 全部转换()
 - 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
 - '先找“字符串”: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
 - texttext = text.Replace(strValue, "")
 - strValuestrValue = strValue.
 
Replace("&", "")- strValuestrValue = strValue.
 
Replace(" ", "")- strValuestrValue = strValue.
 
Replace("ChrW(", "")- strValuestrValue = strValue.
 
Replace(")", "")- Dim chars As Integer =
 
strValue.Length()- charschars = chars \ 5
 - Dim strNew As String = ""
 - For i As Integer = 0 To chars - 1
 - Dim x As String = strValue.
 
Substring(i * 5, 5)- strNewstrNew = 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
 - '再找单字:" & 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
 - texttext = text.Replace(strValue, "")
 - strValuestrValue = strValue.Replace
 
("&", "")- strValuestrValue = strValue.Replace
 
(" ", "")- strValuestrValue = strValue.Replace
 
("ChrW(", "")- strValuestrValue = strValue.Replace
 
(")", "")- strValuestrValue = 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
 - '再找单字:" & 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
 - texttext = text.Replace(strValue, "")
 - strValuestrValue = strValue.Replace
 
("&", "")- strValuestrValue = strValue.Replace
 
(" ", "")- strValuestrValue = strValue.Replace
 
("ChrW(", "")- strValuestrValue = strValue.Replace
 
(")", "")- strValuestrValue = 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.Regular
 
Expressions.Match- '再找单字: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
 - texttext = text.Replace(strValue, "")
 - strValuestrValue = strValue.
 
Replace("&", "")- strValuestrValue = strValue.
 
Replace(" ", "")- strValuestrValue = strValue.
 
Replace("ChrW(", "")- strValuestrValue = strValue.
 
Replace(")", "")- strValuestrValue = 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- '***单字: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
 - texttext = text.Replace(strValue, "")
 - strValuestrValue = strValue.
 
Replace(" ", "")- strValuestrValue = strValue.
 
Replace("ChrW(", "")- strValuestrValue = 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 Function
 - End Module
 
VB.NET汉字转换的相关代码就为大家介绍到这里。
                网站栏目:VB.NET汉字转换详细操作步骤介绍
                
                标题路径:http://www.csdahua.cn/qtweb/news30/397430.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网