LoginSignup
0
0

More than 5 years have passed since last update.

c++ builder XE4, 10.2 Tokyo > TMemo > 行頭からのバイト数を数える

Last updated at Posted at 2015-09-03
動作確認
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など)が何文字目にあるかなどをチェックするのに使える。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0