unsigned int ChineseToNumber(const std::string& chnString) { unsigned int rtn = 0; unsigned int section = 0; int number = 0; bool secUnit = false; std::string::size_type pos = 0; while(pos < chnString.length()) { int num = ChineseToValue(chnString.substr(pos, CHN_CHAR_LENGTH)); if(num >= 0) /*数字还是单位?*/ { number = num; pos += CHN_CHAR_LENGTH; if(pos >= chnString.length())//如果是最后一位数字,直接结束 { section += number; rtn += section; break; } } else { int unit = ChineseToUnit(chnString.substr(pos, CHN_CHAR_LENGTH), secUnit); if(secUnit)//是节权位说明一个节已经结束 { section = (section + number) * unit; rtn += section; section = 0; } else { section += (number * unit); } number = 0; pos += CHN_CHAR_LENGTH; if(pos >= chnString.length()) { rtn += section; break; } } } return rtn; }
void MainWindow::setmynum(QString str) { unsigned int rtn = 0; unsigned int section = 0; int number = 0; bool secUnit = false; int pos = 0; while(pos<str.length()) { int num = ChineseToValue(str.mid(pos, 1)); if(num >= 0) { number = num; ++pos; if(pos >= str.length()) { section += number; rtn += section; break; } } else { int unit = ChineseToUnit(str.mid(pos,1),secUnit); if(secUnit) { section = (section + number) * unit; rtn += section; section = 0; } else { section += (number * unit); } number = 0; ++pos; if(pos >= str.length()) { rtn += section; break; } } } QString s = QString::number(rtn); ui->lineEdit_3->setText(s); }