在MEMO里将0x12,0x34,0x71,0x28,转换成0x21,0x43,0x17,0x82,
在MEMO里将0x12,0x34,0x71,0x28,转换成0x21,0x43,0x17,0x82,代码如何实现,刚开始学习BCB。请大家帮忙一下。
[解决办法]
TStringList *pList = new TStringList() ;
pList->Delimiter = ',' ;
pList->DelimitedText = Memo1->Text ;
Memo1->Clear() ;
int tmpInt = 0 ;;
for(int i = 0; i < pList->Count; i++)
{
tmpInt = pList->Strings[i].ToIntDef(0) ;
tmpInt<<= 4 ;
tmpInt
[解决办法]
= (tmpInt>>8) ;
tmpInt &= 0xff ;
Memo1->Text = Memo1->Text + "0x" + IntToHex(tmpInt,2) + ",";
}
delete pList ;
//把你的代码稍微修改了一下,bcb6下调试过
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String str;
char ch;
int n = StrToInt(Memo1->Lines->Count);//取得MEMO里有多少行
int tmp;
for(int i=0; i<n; i++)
{
str=Memo1->Lines->Strings[i]; //取行字符串
tmp = str.Length(); //取得行字符串的字符数
for(int j=0; j<tmp/5; j++)
{ //执行第3和第4位的字符交换(注意这里的下标是从1开始的)
ch=str[j*5+3];
str[j*5+3]=str[j*5+4];
str[j*5+4]=ch;
}
Memo1->Lines->Strings[i] = str;//显示转换后一行字符串
}
}