ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • StrictDelimiter
    C++ Builder/이벤트 속성 2019. 1. 28. 08:58
    [989] [String] TStringList 의 StrictDelimiter 프로퍼티란?
    장성호 [nasilso]12293 읽음    2010-06-09 18:05
    음.. 

    C++Builder6, Delphi7에는 없지만.. 

    RAD2007이상버젼에서는 
    TStringList 에 StrictDelimiter라는 bool형 프로퍼티가 있습니다. 

    아는 사람은 알겠지만.. 
    새로 생긴 프로퍼티라서 혹 모르시는 분이 있으실것 같아 적어봅니다. 

    뭐 이름 그대로 구분자(Delimiter)를 엄격하게(Strict)한다는 뜻이겠죠~! 

    다음과 같은 문자열이 있을경우에 StrictDelimiter를 쓰고 안쓰고 결과가 다릅니다. 

    1
    2
    3
    4
    5
    6
    7
    8
    9
    TStringList *lst=new TStringList;
    lst->Delimiter='$';
    lst->DelimitedText="1111$2  22$3333$4444";
    //위와같이 할경우 다음과 같이 결과가 나옵니다.
    lst->Strings[0]; // "1111";
    lst->Strings[1]; // "2";
    lst->Strings[2]; // "22";
    lst->Strings[3]; // "3333";
    lst->Strings[4]; // "4444";


    그냥 Delimiter로 '$'를 주었지만 공백(space)문자도 Default로 Delimiter로 쓰여지기 때문입니다. 


    그런데 똑같은 문자열에서 StrictDelimiter=true로 해서 짜르면.. 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    TStringList *lst=new TStringList;
    lst->StrictDelimiter=true;
    lst->Delimiter='$';
    lst->DelimitedText="1111$2  22$3333$4444";
     
    //위와같이 할경우 다음과 같이 결과가 나옵니다.
    lst->Strings[0]; // "1111";
    lst->Strings[1]; // "2  22";
    lst->Strings[2]; // "3333";
    lst->Strings[3]; // "4444";


    StrictDelimiter는 DelimitedText에만 영향을 끼치는것이 아니라 
    CommaText에도 영향을 미칩니다. 
    CommaText에서도 Default-Delimiter로 space(' ')와 comma(',')등이  같이 쓰이는데.. 
    StrictDelimiter를 true사용하면 space는 Delimiter에서 제외되는것입니다. 

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    TStringList *lst=new TStringList;
    lst->StrictDelimiter=false;
    lst->CommaText=="1111,2 22,\"33  333\",4444";
    //--------------------
    //StrictDelimiter=false;로하면 다음과 같이 되구
    lst->Strings[0]; // "1111";
    lst->Strings[1]; // "2";
    lst->Strings[2]; // "22";
    lst->Strings[3]; // "33 333";
    lst->Strings[4]; // "4444";
     
    delete lst;


    그리구.. 

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    TStringList *lst=new TStringList;
    lst->StrictDelimiter=true;
    lst->CommaText=="1111,2 22,\"33  333\",4444";
    //--------------------
    //StrictDelimiter=true;로하면 다음과 같이 됩니다.
    lst->Strings[0]; // "1111";
    lst->Strings[1]; // "2 22";
    lst->Strings[2]; // "33 333";
    lst->Strings[3]; // "4444";
     
    delete lst;


    ------------------------------------------------------------------------------------- 
    앗참 한가지더.. 

    StrictDelimiter프로퍼니는 
    CommaText나 DelimitedText프로퍼티의 Set에만 동작하는것이 아니라 Get에도 동작합니다. 

    StrictDelimiter=true; 로해서 DelimitedText를 만들어 보면 다음과 같습니다. 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    TStringList *lst=new TStringList;
    lst->StrictDelimiter=true;
    lst->Delimiter='$';
    lst->Add("1111");
    lst->Add("2222");
    lst->Add("33 33");
    lst->Add("4444");
    ShowMessage(lst->DelimitedText); //내용은 "1111$2222$33 33$4444"
    delete lst;


    위 코드에서 StrictDelimiter=false로 해서 쓰면 어떻게 될까요? 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    TStringList *lst=new TStringList;
    lst->StrictDelimiter=false;
    lst->Delimiter='$';
    lst->Add("1111");
    lst->Add("2222");
    lst->Add("33 33");
    lst->Add("4444");
    ShowMessage(lst->DelimitedText); //내용은 "1111$2222$\"33 33\"$4444"
    delete lst;



    리스트에 Add한 문자열중 
    공백 space(' ') 이 있는 문자열은 쌍따옴표('"')로 묶여지게 됩니다. 

    CommaText에도 똑같이 동작하구요.. 

    그럼..

    출처: http://www.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=989


    728x90

    'C++ Builder > 이벤트 속성' 카테고리의 다른 글

    OnKeyPress  (0) 2018.12.06

    댓글

Designed by Tistory.