如:山东 输入字母S 或 SD 就能检索出来
12 个解决方案
#3
地名啊,提前填进去的...
#4
你可以用码表,把用户输入的中文先转成拼音,再专门保存到一个字段。
#5
如果只是地名,就在数据库中存放所有地名及拼音首字母
不是地名就不知道了
不是地名就不知道了
#6
谢谢大家了!
#7
mark
#8
#9
SQL函数取汉字拼音首字母
create function comm_getpy
(
@str nvarchar(4000)
)
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
set @word=left(@str,1)
--如果非汉字字符,返回原字符
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (
select top 1 PY
from
(
select 'A' as PY,N'驁' as word
union all select 'B',N'簿'
union all select 'C',N'錯'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鰒'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'漚'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'籜'
union all select 'W',N'鶩'
union all select 'X',N'鑂'
union all select 'Y',N'韻'
union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC
)
else @word
end)
set @str=right(@str,len(@str)-1)
end
return @PY
end
#10
C#代码
/// <summary>
/// /// 取单个字符的拼音声母/// Code By MuseStudio@hotmail.com
/// /// 2004-11-30/// </summary>/// <param name="c">要转换的单个汉字</param>
/// /// <returns>拼音声母</returns>
public static string GetPYChar(string c)
{
byte[] array = new byte[2];
array = System.Text.Encoding.Default.GetBytes(ClearNullFunction(c));
int i = (short)(array[0] - '\0') * 256 + ((short)(array[1] - '\0'));
if (i < 0xB0A1) return "*";
if (i < 0xB0C5) return "a";
if (i < 0xB2C1) return "b";
if (i < 0xB4EE) return "c";
if (i < 0xB6EA) return "d";
if (i < 0xB7A2) return "e";
if (i < 0xB8C1) return "f";
if (i < 0xB9FE) return "g";
if (i < 0xBBF7) return "h";
if (i < 0xBFA6) return "j";
if (i < 0xC0AC) return "k";
if (i < 0xC2E8) return "l";
if (i < 0xC4C3) return "m";
if (i < 0xC5B6) return "n";
if (i < 0xC5BE) return "o";
if (i < 0xC6DA) return "p";
if (i < 0xC8BB) return "q";
if (i < 0xC8F6) return "r";
if (i < 0xCBFA) return "s";
if (i < 0xCDDA) return "t";
if (i < 0xCEF4) return "w";
if (i < 0xD1B9) return "x";
if (i < 0xD4D1) return "y";
if (i < 0xD7FA) return "z";
return "*";
}
#endregion
#11
如果是前台处理,先提取数据再转换拼音。
如果是后台处理,效率高一些。(利用上面函数的取数,在表里添加一列拼音简写列)
如果是后台处理,效率高一些。(利用上面函数的取数,在表里添加一列拼音简写列)
#12
mark
#1
#2
#3
地名啊,提前填进去的...
#4
你可以用码表,把用户输入的中文先转成拼音,再专门保存到一个字段。
#5
如果只是地名,就在数据库中存放所有地名及拼音首字母
不是地名就不知道了
不是地名就不知道了
#6
谢谢大家了!
#7
mark
#8
#9
SQL函数取汉字拼音首字母
create function comm_getpy
(
@str nvarchar(4000)
)
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
set @word=left(@str,1)
--如果非汉字字符,返回原字符
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (
select top 1 PY
from
(
select 'A' as PY,N'驁' as word
union all select 'B',N'簿'
union all select 'C',N'錯'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鰒'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'漚'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'籜'
union all select 'W',N'鶩'
union all select 'X',N'鑂'
union all select 'Y',N'韻'
union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC
)
else @word
end)
set @str=right(@str,len(@str)-1)
end
return @PY
end
#10
C#代码
/// <summary>
/// /// 取单个字符的拼音声母/// Code By MuseStudio@hotmail.com
/// /// 2004-11-30/// </summary>/// <param name="c">要转换的单个汉字</param>
/// /// <returns>拼音声母</returns>
public static string GetPYChar(string c)
{
byte[] array = new byte[2];
array = System.Text.Encoding.Default.GetBytes(ClearNullFunction(c));
int i = (short)(array[0] - '\0') * 256 + ((short)(array[1] - '\0'));
if (i < 0xB0A1) return "*";
if (i < 0xB0C5) return "a";
if (i < 0xB2C1) return "b";
if (i < 0xB4EE) return "c";
if (i < 0xB6EA) return "d";
if (i < 0xB7A2) return "e";
if (i < 0xB8C1) return "f";
if (i < 0xB9FE) return "g";
if (i < 0xBBF7) return "h";
if (i < 0xBFA6) return "j";
if (i < 0xC0AC) return "k";
if (i < 0xC2E8) return "l";
if (i < 0xC4C3) return "m";
if (i < 0xC5B6) return "n";
if (i < 0xC5BE) return "o";
if (i < 0xC6DA) return "p";
if (i < 0xC8BB) return "q";
if (i < 0xC8F6) return "r";
if (i < 0xCBFA) return "s";
if (i < 0xCDDA) return "t";
if (i < 0xCEF4) return "w";
if (i < 0xD1B9) return "x";
if (i < 0xD4D1) return "y";
if (i < 0xD7FA) return "z";
return "*";
}
#endregion
#11
如果是前台处理,先提取数据再转换拼音。
如果是后台处理,效率高一些。(利用上面函数的取数,在表里添加一列拼音简写列)
如果是后台处理,效率高一些。(利用上面函数的取数,在表里添加一列拼音简写列)
#12
mark