Qt中的QString 转化到标准C++ 中的string进行操作。
QString Translation::getLetter(QString strText)
{
bool m_LetterEnd=false;
//转换标准string操作
std::string stdstrText = strText.toStdString();
unsigned char ucHigh, ucLow;
int m_nCode = 0;
std::string stdstrValue="";
for (int i=0; i<stdstrText.length(); i++)
{
//判断是否是汉字
if ( (unsigned char)stdstrText[i] < 0x80 )
{
stdstrValue=stdstrValue+stdstrText[i];
if(m_LetterEnd) stdstrValue=stdstrValue+'/';
continue;
}
//汉字处理
ucHigh = (unsigned char)stdstrText[i];
ucLow = (unsigned char)stdstrText[i+1];
if ( ucHigh < 0xa1 || ucLow < 0xa1)
continue;
else
m_nCode = (ucHigh - 0xa0) * 100 + ucLow - 0xa0;
//汉字转码
std::string stdstrRes=(findLetter(m_nCode)).toStdString();
stdstrValue=stdstrValue+stdstrRes;
i++;
if(m_LetterEnd) stdstrValue=stdstrValue+'/';
}
//string->Qstring
QString strValue = QString::fromStdString(stdstrValue);
strValue = strValue.toLower();
return strValue;
}