新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
VB.NET漢字轉(zhuǎn)換詳細(xì)操作步驟介紹
VB.NET開發(fā)環(huán)境的出現(xiàn),幫助開發(fā)人員實現(xiàn)了許多特定的功能需求。比如在對移動設(shè)備的操作方面等。VB.NET漢字轉(zhuǎn)換中若使用Reflector,而且程序中有中文字符,Reflector會用代碼表示。若反成C#,網(wǎng)上有很多解決方案了,而VB.NET卻找不到。VB.NET里可能更復(fù)雜些,畢竟C#還是一個完整的字符串,而VB中卻被拆成一個一個單字,然后用&連接。#t#

10年積累的網(wǎng)站建設(shè)、成都網(wǎng)站制作經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先做網(wǎng)站后付款的網(wǎng)站建設(shè)流程,更有凌河免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
下面這段VB.NET漢字轉(zhuǎ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.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漢字轉(zhuǎn)換的相關(guān)代碼就為大家介紹到這里。
本文標(biāo)題:VB.NET漢字轉(zhuǎn)換詳細(xì)操作步驟介紹
文章起源:http://m.fisionsoft.com.cn/article/djjhpgd.html


咨詢
建站咨詢
