首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

汉字转拼音乱码

2012-11-06 
汉字转拼音乱码,求助比方说 输入“比如”,点击转换后,输出的就是“# @繵i”,求大大帮帮忙AnsiString__fastcal

汉字转拼音乱码,求助
比方说 输入“比如”,点击转换后,输出的就是“# @繵i”,求大大帮帮忙
AnsiString __fastcall TForm1::ConvertHZToPYp(AnsiString str)
{
  static int li_SecPosValue[]={1601,1637,1833,2078,2274,2302,2433,2594,2787,3106,3212,3472,3635,3722,3730,3858,4027,4086,4390,4558,4684,4925,5249};
  static char* lc_FirstLetter[] = {"A", "B","C","D","E","F","G","H","J","K","L","M","N","O","P","Q","R","S","T","W","X","Y","Z"};
  static char* ls_SecondSecTable =
  "CJWGNSPGCGNE[Y[BTYYZDXYKYGT[JNNJQMBSGZSCYJSYY[PGKBZGY[YWJKGKLJYWKPJQHY[W[DZLSGMRYPYWWCCKZNKYYGTTNJJNYKKZYTCJNMCYLQLYPYQFQRPZSLWBTGKJFYXJWZLTBNCXJJJJTXDTTSQZYCDXXHGCK[PHFFSS[YBGXLPPBYLL[HLXS[ZM[JHSOJNGHDZQYKLGJHSGQZHXQGKEZZWYSCSCJXYEYXADZPMDSSMZJZQJYZC[J[WQJBYZPXGZNZCPWHKXHQKMWFBPBYDTJZZKQHY"
  ....... ;
  AnsiString result = "";
  int H,L,W;
  char *as_HzString;
  int stringlen = strlen(as_HzString);
   
  for(int i = 0; i < stringlen; i ++ )
  {  
  H = (unsigned char)(as_HzString[i]);  
  L = (unsigned char)(as_HzString[i+1]);  
  if(H < 0xA1 || L < 0xA1)
  {  
  result += as_HzString[i];  
  continue;  
  }  
  else W = (H - 160) * 100 + L - 160;
  if(W > 1600 && W < 5590)
  {
  for(int j = 22; j >= 0; j --)
  if(W >= li_SecPosValue[j])
  {
  result += lc_FirstLetter[j];
  i++;
  break;
  }
  continue;
  }  
  else
  {
  i++;  
  W = ( H - 160 - 56 )*94 + L - 161;  
  if(W >= 0 && W <= 3007)  
  result += ls_SecondSecTable[W];  
  else
  {  
  result += (char)H;
  result += (char)L;
  }
  }
  }
  return result;
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  AnsiString str;
  Edit1->Text = str;//输入汉字到文本框1
  Edit2->Text=ConvertHZToPYp(str); //文本框2转换出拼音
}

[解决办法]
这个函数不对,原始的函数不要改,你试试这个

void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString str;
str = Edit1->Text ;//输入汉字到文本框1
Edit2->Text=ConvertHZToPYp(str.c_str()); 这里先转成char *
}
AnsiString __fastcall TForm1::ConvertHZToPYp(char *as_HzString);
...
[解决办法]
我这个是正确的

.h文件

C/C++ code
#ifndef Unit1H#define Unit1H//---------------------------------------#include <Classes.hpp>#include <Controls.hpp>#include <StdCtrls.hpp>#include <Forms.hpp>//---------------------------------------class TForm1 : public TForm{__published:    // IDE-managed Components        TButton *Button1;        TEdit *Edit1;        TEdit *Edit2;        void __fastcall Button1Click(TObject *Sender);        void __fastcall FormCreate(TObject *Sender);private:    // User declarationsAnsiString   __fastcall   ConvertHZToPY(char   *as_HzString);public:        // User declarations        __fastcall TForm1(TComponent* Owner);};//---------------------------------------extern PACKAGE TForm1 *Form1;//---------------------------------------#endif 


[解决办法]
怎么回事啊,现在对字数限制得太少了
[解决办法]

探讨
先谢谢两位,可以了,问个问题,static char* ls_SecondSecTable 这个里面是什么意思,不懂

热点排行