[置顶] Qt 汉字内码及区位码 提取


工具下载:http://download.csdn.net/detail/qustdjx/6809217

源代码:

void MainWindow::on_pushButton_clicked()
{
    QString text_str=ui->lineEdit->text();
  if(text_str.length()>0)
  {
  const char *hanzi=qPrintable(text_str);
      QByteArray ba(hanzi);
  char *data = ba.data();



    //printf("%x",data[0]);
    //printf("%x",data[1]);
  char s[8];
    s[0]='0';
    s[1]='0';
    s[2]='0';
    s[3]='0';
    s[4]='0';
    s[5]='0';
    s[6]='0';
    s[7]='0';


  sprintf(s, "%x", data[0]);
  QString qstr1 = QString::fromStdString(s);
  sprintf(s, "%x", data[1]);
  QString qstr2 = QString::fromStdString(s);
  QString s1=qstr1.right(2);
  QString s2=qstr2.right(2);
  bool ok;
  int quwei=(s1.toUpper()+s2.toUpper()).toInt(&ok,16)-0xA0A0;
  QString qstr3=QString::number(quwei,16);

  int num_1=Str2Int(qstr3.left(1))*16+Str2Int(qstr3.mid(1,1));

  int num_2=Str2Int(qstr3.mid(2,1))*16+Str2Int(qstr3.mid(3,1));

  QString quwei_1,quwei_2;
  if(num_1<10)
  {
      quwei_1="0"+QString::number(num_1);
  }
  else
  {
      quwei_1=QString::number(num_1);
  }

  if(num_2<10)
  {
      quwei_2="0"+QString::number(num_2);
  }
  else
  {
      quwei_2=QString::number(num_2);
  }
  ui->lineEdit_2->setText(s1.toUpper()+s2.toUpper());
  ui->lineEdit_3->setText(quwei_1+quwei_2);

}
}

int MainWindow::Str2Int(QString st)
{
    int num;
    bool ok;

        if(st=="a")
        {
            return 10;
        }
        else if (st=="b")
        {
          return 11;
        }
        else if (st=="c")
        {
           return 12;
        }
        else if (st=="d")
        {
            return 13;
        }
        else if (st=="e")
        {
          return 14;
        }
        else if (st=="f")
        {
          return 15;
        }
       else
      {
       num=st.toInt(&ok,10) ;
       return num;
      }
}

运行效果图:

[置顶] Qt 汉字内码及区位码 提取_第1张图片

你可能感兴趣的:([置顶] Qt 汉字内码及区位码 提取)