本篇文章給大家分享的是有關(guān)VB.NET中怎么實(shí)現(xiàn)漢字轉(zhuǎn)換,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比廣饒網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式廣饒網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋廣饒地區(qū)。費(fèi)用合理售后完善,十多年實(shí)體公司更值得信賴。
下面這段VB.NET漢字轉(zhuǎn)換代碼解決了這個(gè)問題,將其拷到宏編輯器里保存即可,寫的有點(diǎn)傻傻的,懶得優(yōu)化了,好使就行:)
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Imports System.Text.
RegularExpressions
Public Module Unicode2
Character
'必須手工選擇到單字
Public Sub 單字轉(zhuǎn)換()
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
'全部替換當(dāng)前文件的漢字
Public Sub 全部轉(zhuǎn)換()
Dim doc As Document =
DTE.ActiveDocumentDim docText As TextDocument =
doc.ObjectDim 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 CharDim 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 CharDim ch As Char = ChrW(int)
Return ch
End Function
End Module
以上就是VB.NET中怎么實(shí)現(xiàn)漢字轉(zhuǎn)換,小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識(shí)。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
標(biāo)題名稱:VB.NET中怎么實(shí)現(xiàn)漢字轉(zhuǎn)換
分享路徑:http://www.rwnh.cn/article16/ipcjdg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、全網(wǎng)營銷推廣、網(wǎng)站維護(hù)、網(wǎng)站導(dǎo)航、App設(shè)計(jì)、網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)