请问妖哥,字符串问题
AnsiString str = "春眠不觉晓处处闻啼鸟";AnsiString strLine;int i = 0;BYTE a, b;while (i < str.Length()){ a = (BYTE)str[++i]; b = (BYTE)str[++i]; strLine.sprintf("%02X%02X", a, b); Memo1->Lines->Add(strLine);}
isprint
[解决办法]
AnsiString str = "春眠不觉aa晓处1处闻啼鸟";AnsiString strLine;int i = 1;BYTE a, b;while (i < str.Length()){ switch (ByteType(str, i)) { case mbLeadByte: { a = (BYTE)str[i++]; break; } case mbTrailByte: { b = (BYTE)str[i++]; strLine.sprintf("%02X%02X", a, b); Memo1->Lines->Add(strLine); break; } case mbSingleByte: { a = (BYTE)str[i++]; strLine.sprintf("%02X", a); Memo1->Lines->Add(strLine); break; } default: break; }}
[解决办法]
检测BYTE值是否>0x80如果大于只取两个字节,否则只取一个字节