Q&A

  • 문자열추출
DB에 Q130 / JOB| PRC OP QTY 형태로 입력되었고
이걸 Memo1에           Memo2엔
Q130                        PRC
/                               OP
JOB                           QTY  형태로 추출 하고 싶은데.. 고수님들 도와주세여

참 추출기준 문자는 | 입니다.
2  COMMENTS
  • Profile
    석주현 2005.05.04 19:29
    아래코드를 참조하세요.

    스트링 처리에서 StringReplace 함수와 ExtractStrings 함수가 많이 쓰입니다.
    그걸 잘 활용하시면 해결됩니다..
    ^^ 그럼 이만

    <!--CodeS-->
    procedure TForm1.Button1Click(Sender: TObject);
    var
        Str           : String;
        ResultStrList : TStringList;
        i             : Integer;
        pMemo         : ^TMemo;
    begin
        Str         := 'Q130 / JOB| PRC OP QTY';

        ResultStrList := TStringList.Create;
        Str := StringReplace(Str,'|', ' |', [rfreplaceAll]);
        ExtractStrings([' '], [#0], PAnsiChar(Str), ResultStrList);

        pMemo := @Memo1;
        for i:=0 to ResultStrList.Count - 1 do
          begin
            if ResultStrList.Strings[i] = '|' then
               pMemo := @Memo2
            else
               pMemo^.Lines.Add(ResultStrList.Strings[i]);
          end;
    end;
    <!--CodeE-->
  • Profile
    민스맘 2005.05.04 18:57



    pos를 이용해서 |의 위치를 알아낸 다음 Copy를 이용하면 되겠네요