動作確認
C++ Builder XE4
Rad Studio 10.2 Tokyo Update 2 (追記: 2017/12/26)
TMemoに表示されている文字列に関して、行頭からのバイト数を数えたい。
TMemoのKyeUpにて以下を実装する。
参考
http://www.geocities.jp/asumaroyuumaro/program/tips/memolineindex.html
void __fastcall TForm1::Memo1KeyUp(TObject *Sender, WORD &Key, TShiftState Shift)
{
int lineidx, linest;
lineidx = Memo1->Perform(EM_LINEFROMCHAR, UINT(-1), 0);
linest = Memo1->Perform(EM_LINEINDEX, UINT(-1), 0);
int pos = Memo1->SelStart - linest;
L_pos->Caption = String().sprintf(L"%d バイト(配列の[%d])", pos, pos - 1);
}
通信キャプチャした文字列において特定の文字(Bなど)が何文字目にあるかなどをチェックするのに使える。