如何用vb.net将汉字转换成拼音阿 在vb中怎样实现汉字转换为拼音

作者&投稿:寇彩 (若有异议请与网页底部的电邮联系)
public string hz2py(string hz) //获得汉字的区位码
{
byte[] sarr = System.Text.Encoding.Default.GetBytes(hz);
int len = sarr.Length;
if (len>1)
{
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="*";//找不到拼音码的用*补位

if(tmp>=45217&&tmp<=45252){getpychar= "A";}
else if(tmp>=45253&&tmp<=45760){getpychar= "B";}
else if(tmp>=47761&&tmp<=46317){getpychar= "C";}
else if(tmp>=46318&&tmp<=46825){getpychar= "D";}
else if(tmp>=46826&&tmp<=47009){getpychar= "E";}
else if(tmp>=47010&&tmp<=47296){getpychar= "F";}
else if(tmp>=47297&&tmp<=47613){getpychar= "G";}
else if(tmp>=47614&&tmp<=48118){getpychar= "H";}
else if(tmp>=48119&&tmp<=49061){getpychar= "J";}
else if(tmp>=49062&&tmp<=49323){getpychar= "K";}
else if(tmp>=49324&&tmp<=49895){getpychar= "L";}
else if(tmp>=49896&&tmp<=50370){getpychar= "M";}
else if(tmp>=50371&&tmp<=50613){getpychar= "N";}
else if(tmp>=50614&&tmp<=50621){getpychar= "O";}
else if(tmp>=50622&&tmp<=50905){getpychar= "P";}
else if(tmp>=50906&&tmp<=51386){getpychar= "Q";}
else if(tmp>=51387&&tmp<=51445){getpychar= "R";}
else if(tmp>=51446&&tmp<=52217){getpychar= "S";}
else if(tmp>=52218&&tmp<=52697){getpychar= "T";}
else if(tmp>=52698&&tmp<=52979){getpychar= "W";}
else if(tmp>=52980&&tmp<=53640){getpychar= "X";}
else if(tmp>=53689&&tmp<=54480){getpychar= "Y";}
else if(tmp>=54481&&tmp<=55289){getpychar= "Z";}
return getpychar;
}
else
{
return hz;
}
}

public string transpy(string strhz) //把汉字字符串转换成拼音码
{
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'

函数:
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.NET中怎么实现 汉字转换拼音呢~

建立一个表,每个拼音都跟多个汉字对应。可以通过汉字,找出对应的一个拼音,也可以通过拼音,找出一堆汉字。

public string hz2py(string hz) //获得汉字的区位码
{
byte[] sarr = System.Text.Encoding.Default.GetBytes(hz);
int len = sarr.Length;
if (len>1)
{
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="*";//找不到拼音码的用*补位

if(tmp>=45217&&tmp<=45252){getpychar= "A";}
else if(tmp>=45253&&tmp<=45760){getpychar= "B";}
else if(tmp>=47761&&tmp<=46317){getpychar= "C";}
else if(tmp>=46318&&tmp<=46825){getpychar= "D";}
else if(tmp>=46826&&tmp<=47009){getpychar= "E";}
else if(tmp>=47010&&tmp<=47296){getpychar= "F";}
else if(tmp>=47297&&tmp<=47613){getpychar= "G";}
else if(tmp>=47614&&tmp<=48118){getpychar= "H";}
else if(tmp>=48119&&tmp<=49061){getpychar= "J";}
else if(tmp>=49062&&tmp<=49323){getpychar= "K";}
else if(tmp>=49324&&tmp<=49895){getpychar= "L";}
else if(tmp>=49896&&tmp<=50370){getpychar= "M";}
else if(tmp>=50371&&tmp<=50613){getpychar= "N";}
else if(tmp>=50614&&tmp<=50621){getpychar= "O";}
else if(tmp>=50622&&tmp<=50905){getpychar= "P";}
else if(tmp>=50906&&tmp<=51386){getpychar= "Q";}
else if(tmp>=51387&&tmp<=51445){getpychar= "R";}
else if(tmp>=51446&&tmp<=52217){getpychar= "S";}
else if(tmp>=52218&&tmp<=52697){getpychar= "T";}
else if(tmp>=52698&&tmp<=52979){getpychar= "W";}
else if(tmp>=52980&&tmp<=53640){getpychar= "X";}
else if(tmp>=53689&&tmp<=54480){getpychar= "Y";}
else if(tmp>=54481&&tmp<=55289){getpychar= "Z";}
return getpychar;
}
else
{
return hz;
}
}

public string transpy(string strhz) //把汉字字符串转换成拼音码
{
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'

函数:
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怎么把汉字转换成gbk编码
答:vb 怎么把汉字转换成gbk编码参考方法如下:面的两段VB代码分别针对UTF-8(UTF8EncodeURI)和GB2312(GBKEncodeURI)进行了编码的转换。Private Sub command1_click()Debug.Print (UTF8EncodeURI("汉字"))Debug.Print (GBK...

VB.NET中怎样拼接字符串好
答:vb中可以使用+连接字符串,也可以使用&连接字符串,建议使用&连接字符串,以区别数学运算符+。

VB编程,如何将4字节汉字的区位码转换为对应的汉字?
答:在VB编程中,可以通过将4字节汉字的区位码转换为Unicode编码,然后再将Unicode编码转换为汉字实现将4字节汉字的区位码转换为对应的汉字。具体实现可以参考下面的代码:' 定义将区位码转换为汉字的函数 Public Function ConvertGB...

在VB语言中如何将汉字转换成或者ASCII代码?
答:用asc()函数,例如asc(字)...但每次只能转一个字符,例如asc(字符)和asc(字)是一样的,可以用mid()函数逐步取字来逐步转换.

关于VB中textbox中IMEMODE的问题
答:当 IMEMode 属性被设置为 0 时,可以使用 IMEStatus 函数确定当前的 IME 状态。 1 IME 打开。该数值表明 IME 已经被打开,可以输入汉字或日文字符。该设置仅对日文、简体汉字和繁体汉字 IME 有效。 2 IME 关闭。该模式表明 IME 被...

vb 怎么把汉字转换成gbk编码
答:vb 怎么把汉字转换成gbk编码 参考方法如下:面的两段VB代码分别针对UTF-8(UTF8EncodeURI)和GB2312(GBKEncodeURI)进行了编码的转换。Private Sub command1_click()Debug.Print (UTF8EncodeURI("汉字"))Debug.Print (...

VB.NET 类似/u660e的字符串转换为中文
答:你可以用 Encoding 对象转。先用 Encoding.Unicode 转成 Byte(),再转回 Ansi。也可以自己写代码,把/u替换为&H,再逐个用ChrW()函数取得汉字即可。

有哪些可以把汉字变成拼音的软件??
答:汉字上面有拼音的软件有:《汉字拼音转换》、《汉语字典》、《拼音宝》、《洪恩拼音》、《猫小帅拼音》等。1、《汉字拼音转换》《汉字拼音转换》软件是一种可以帮助用户快速将汉字转换为拼音的工具。这些软件不仅支持翻译功...

怎样在EXCEL中自动生成拼音
答:3、此时就出现拼音了。4、接着选中D2单元格,向下拖动鼠标。5、所有姓名都自动生成拼音了。6、输入公式“=PROPER(D2)”,按回车确认,可以将首字母改成大写。7、最后首字母就变成大写了。注意事项:1、在使用excel表格的...

vb.net 中 \uxxxx这类的编码实现转换成中文
答:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim S1 As String Dim S2 As String Dim S3 As String Dim I1 As String S1 = "\u652f\u4ed8...