GB2312是GBK編碼的子集,使用GBK編碼函數(shù)即可

創(chuàng)新互聯(lián)建站主要從事成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、成都外貿(mào)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)綏濱,十載網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):028-86922220
'GBK編碼(結(jié)果以百分號(hào)%進(jìn)行分隔)
Public Function GBKEncode(ByVal sInput As String) As String
Dim ret_GBKEncode As String = ""
Dim i As Integer
Dim startIndex As Integer = 0
Dim endIndex As Integer
Dim x() As Byte = System.Text.Encoding.Default.GetBytes(sInput) '字符以及字符串在vb2008中都是以u(píng)nicode編碼存儲(chǔ)的
endIndex = x.Length - 1
For i = startIndex To endIndex
ret_GBKEncode = "%" Hex(x(i))
Next
Return ret_GBKEncode
End Function
'GBK解碼
Public Function GBKDecode(ByVal sInput As String) As String
sInput = sInput.Replace("%", "")
Dim ret_GBKDecode As String = ""
Dim sLen As Integer = sInput.Length
Dim n As Integer = sLen \ 2
Dim sBytes(0 To n - 1) As Byte
'轉(zhuǎn)化為字節(jié)碼
For i As Integer = 1 To n
sBytes(i - 1) = CByte("H" sInput.Substring(2 * i - 2, 2))
Next
'將字節(jié)碼轉(zhuǎn)化為字符串
ret_GBKDecode = System.Text.Encoding.Default.GetString(sBytes)
Return ret_GBKDecode
End Function
回答補(bǔ)充: 用Chr()函數(shù)把a(bǔ)scii碼轉(zhuǎn)化成漢字
用ChrW()函數(shù)把Unicode碼轉(zhuǎn)化成漢字
(還有之前說的
AscW()函數(shù)返回值為負(fù)的時(shí)候,應(yīng)加上65536 才得到漢字實(shí)際的Unicode碼)
----------------------------------------------------------------------------------------
求漢字的Unicode代碼 用AscW()函數(shù)
AscW("漢")=27721
求漢字的ASCII碼 用Asc()函數(shù) 返回一個(gè)負(fù)數(shù)值
如Asc("漢")=-17734
PS:PS:改進(jìn)了下 可轉(zhuǎn)化多個(gè)漢字
在窗體上建三個(gè)text控件,
功能:text1中按個(gè)輸入漢字后 text2中按個(gè)顯示漢字的Unicode代碼 text3中顯示漢字的ASCII碼
原代碼如下:
Private Function change(s As String) As String
change = AscW(s)
If change 0 Then
change = change + 65536
End If
End Function
Private Function change2(s As String) As String
change2 = Asc(s)
End Function
Private Sub Text1_Change()
For i = 1 To Len(Text1.Text)
s = s change(Mid(Text1.Text, i, 1)) " "
Next
Text2.Text = s
s = ""
For i = 1 To Len(Text1.Text)
s = s change2(Mid(Text1.Text, i, 1)) " "
Next
Text3.Text = s
End Sub
補(bǔ)充:a 的ASCII碼是97
Asc函數(shù)返回的是字符串首字母的ASCII碼(如字符串只一個(gè)字符,即返回該字符的ASCII碼)
Asc 函數(shù)
返回一個(gè) Integer,代表字符串中首字母的字符代碼。
語法
Asc(string)
必要的 string 參數(shù)可以是任何有效的字符串表達(dá)式。如果 string 中沒有包含任何字符,則會(huì)產(chǎn)生運(yùn)行時(shí)錯(cuò)誤。
PSPS: VB里 目前我還沒找到能將之轉(zhuǎn)換成 把漢字轉(zhuǎn)換成西歐文編碼的函數(shù) 不敢斷言沒有(有估計(jì)也很難找 我搜了好多關(guān)鍵字都沒找到)
還有 不只是遨游瀏覽器,一般的IE瀏覽器 也有此功能
查看——編碼——其他——最下面那小三角號(hào)——西歐(ISO)
public string hz2py(string hz) //獲得漢字的區(qū)位碼
{
byte[] sarr = System.Text.Encoding.Default.GetBytes(hz);
int len = sarr.Length;
if (len1)
{
byte[] array = new byte[2];
array = System.Text.Encoding.Default.GetBytes(hz);
int i1 = (short)(array[0] - '\0');
int i2 = (short)(array[1] - '\0');
//unicode解碼方式下的漢字碼
// array = System.Text.Encoding.Unicode.GetBytes(hz);
// int i1 = (short)(array[0] - '\0');
// int i2 = (short)(array[1] - '\0');
// int t1 = Convert.ToInt32(i1,16);
// int t2 = Convert.ToInt32(i2,16);
int tmp=i1*256+i2;
string getpychar="*";//找不到拼音碼的用*補(bǔ)位
if(tmp=45217tmp=45252){getpychar= "A";}
else if(tmp=45253tmp=45760){getpychar= "B";}
else if(tmp=47761tmp=46317){getpychar= "C";}
else if(tmp=46318tmp=46825){getpychar= "D";}
else if(tmp=46826tmp=47009){getpychar= "E";}
else if(tmp=47010tmp=47296){getpychar= "F";}
else if(tmp=47297tmp=47613){getpychar= "G";}
else if(tmp=47614tmp=48118){getpychar= "H";}
else if(tmp=48119tmp=49061){getpychar= "J";}
else if(tmp=49062tmp=49323){getpychar= "K";}
else if(tmp=49324tmp=49895){getpychar= "L";}
else if(tmp=49896tmp=50370){getpychar= "M";}
else if(tmp=50371tmp=50613){getpychar= "N";}
else if(tmp=50614tmp=50621){getpychar= "O";}
else if(tmp=50622tmp=50905){getpychar= "P";}
else if(tmp=50906tmp=51386){getpychar= "Q";}
else if(tmp=51387tmp=51445){getpychar= "R";}
else if(tmp=51446tmp=52217){getpychar= "S";}
else if(tmp=52218tmp=52697){getpychar= "T";}
else if(tmp=52698tmp=52979){getpychar= "W";}
else if(tmp=52980tmp=53640){getpychar= "X";}
else if(tmp=53689tmp=54480){getpychar= "Y";}
else if(tmp=54481tmp=55289){getpychar= "Z";}
return getpychar;
}
else
{
return hz;
}
}
public string transpy(string strhz) //把漢字字符串轉(zhuǎn)換成拼音碼
{
string strtemp="";
int strlen=strhz.Length;
for (int i=0;i=strlen-1;i++)
{
strtemp+=hz2py(strhz.Substring(i,1));
}
return strtemp;
}
create table tabpy(id int identity,b_begin varbinary(2),b_end varbinary(2),word varchar(2))
insert tabpy select 0xB0A1, 0xB0C4,'A'
union all select 0xB0C5, 0xB2C0,'B'
union all select 0xB2C1, 0xB4ED,'C'
union all select 0xB4EE, 0xB6E9,'D'
union all select 0xB6EA, 0xB7A1,'E'
union all select 0xB7A2, 0xB8C0,'F'
union all select 0xB8C1, 0xB9FD,'G'
union all select 0xB9FE, 0xBBF6,'H'
union all select 0xBBF7, 0xBFA5,'J'
union all select 0xBFA6, 0xC0AB,'K'
union all select 0xC0AC, 0xC2E7,'L'
union all select 0xC2E8, 0xC4C2,'M'
union all select 0xC4C3, 0xC5B5,'N'
union all select 0xC5B6, 0xC5BD,'O'
union all select 0xC5BE, 0xC6D9,'P'
union all select 0xC6DA, 0xC8BA,'Q'
union all select 0xC8BB, 0xC8F5,'R'
union all select 0xC8F6, 0xCBF9,'S'
union all select 0xCBFA, 0xCDD9,'T'
union all select 0xCDDA, 0xCEF3,'W'
union all select 0xCEF4, 0xD1B8,'X'
union all select 0xD1B9, 0xD4D0,'Y'
union all select 0xD4D1, 0xD7F9,'Z'
函數(shù):
create function getfirstpy(@a varchar(200))
returns varchar(100)
as
begin
declare @i int,@j int,@result varchar(100)
set @result=''
set @i=len(@a)
set @j=1
while @j=@i
begin
select @result=@result+word from tabpy where cast(substring(@a,@j,1) as varbinary(2)) between b_begin and b_end
set @j=@j+1
end
return @result
end
本文名稱:vb點(diǎn)虐
中把漢字轉(zhuǎn)碼 vb轉(zhuǎn)譯字符
標(biāo)題網(wǎng)址:http://chinadenli.net/article46/ddgsseg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷、軟件開發(fā)、服務(wù)器托管、品牌網(wǎng)站設(shè)計(jì)、自適應(yīng)網(wǎng)站、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)