得到汉字拼音码:只得每个字的拼音的第一个字母:
如是:我是中国人。得到:wszgr:
求一算法或过程!

解决方案 »

  1.   

    SQL2000: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 语句:
    select dbo.getfirstpy('中国人')
    --结果:
    ZGR
      

  2.   

    我可以发个取 拼音首字母(同时包括 拼音全码 五笔首字母 五笔全码)的dll用法很简单
      

  3.   

    楼上的代码是用SQL,如果不用SQL数据库呢。
    请注释一下嘛。愿高分相送!!
    大家都来讨论一下。
      

  4.   

    function GetHzPy(const AHzStr: string): string;
    const
    ChinaCode: array[0..25, 0..1] of Integer = ((1601, 1636), (1637, 1832), (1833, 2077),
      (2078, 2273), (2274, 2301), (2302, 2432), (2433, 2593), (2594, 2786), (9999, 0000),
      (2787, 3105), (3106, 3211), (3212, 3471), (3472, 3634), (3635, 3722), (3723, 3729),
      (3730, 3857), (3858, 4026), (4027, 4085), (4086, 4389), (4390, 4557), (9999, 0000),
      (9999, 0000), (4558, 4683), (4684, 4924), (4925, 5248), (5249, 5589));
    var
    i, j, HzOrd: integer;
    begin
    i := 1;
    while i <= Length(AHzStr) do
    begin
      if (AHzStr[i] >= #160) and (AHzStr[i + 1] >= #160) then
      begin
        HzOrd := (Ord(AHzStr[i]) - 160) * 100 + Ord(AHzStr[i + 1]) - 160;
        for j := 0 to 25 do
        begin
          if (HzOrd >= ChinaCode[j][0]) and (HzOrd <= ChinaCode[j][1]) then
          begin
            Result := Result + char(byte('A') + j);
            break;
          end;
        end;
        Inc(i);
      end else Result := Result + AHzStr[i];
      Inc(i);
    end;
    end;
      

  5.   

    function GetPYIndexChar(strChinese: string;bUpCase: Boolean = True): char;
    begin
    case WORD(strChinese[1]) shl 8 + WORD(strChinese[2]) of$B0A1..$B0C4 : result := 'A';$B0C5..$B2C0 : result := 'B';$B2C1..$B4ED : result := 'C';$B4EE..$B6E9 : result := 'D';$B6EA..$B7A1 : result := 'E';$B7A2..$B8C0 : result := 'F';$B8C1..$B9FD : result := 'G';$B9FE..$BBF6 : result := 'H';$BBF7..$BFA5 : result := 'J';$BFA6..$C0AB : result := 'K';$C0AC..$C2E7 : result := 'L';$C2E8..$C4C2 : result := 'M';$C4C3..$C5B5 : result := 'N';$C5B6..$C5BD : result := 'O';$C5BE..$C6D9 : result := 'P';$C6DA..$C8BA : result := 'Q';$C8BB..$C8F5 : result := 'R';$C8F6..$CBF9 : result := 'S';$CBFA..$CDD9 : result := 'T';$CDDA..$CEF3 : result := 'W';$CEF4..$D188 : result := 'X';$D1B9..$D4D0 : result := 'Y';$D4D1..$D7F9 : result := 'Z';elseresult := char(0);end;if not bUpCase thenbegin // 转换为小写result := Chr(Ord(result)+32);end;end;function GetPYIndexStr(strChinese: string;bUpCase: Boolean = True): string;varstrChineseTemp : string;cTemp : Char;beginresult := '';strChineseTemp := strChinese;while strChineseTemp<>'' dobegincTemp := GetPYIndexChar(strChineseTemp);if not bUpCase thenbegin // 转换为小写cTemp := Chr(Ord(cTemp)+32);end;result := result + string(cTemp);strChineseTemp := Copy(strChineseTemp,3,Length(strChineseTemp));end;end;end. 
      

  6.   

    补充一下,代码是COPY来的,我自己一直在用^..^
      

  7.   

    [email protected]
    请发给我答案。谢谢!