Delphi의 문자열 함수(6) - StrUtils의 Ansi 문자열 함수

3409 단어 Delphi


//               : AnsiLeftStr、AnsiRightStr

var

  ss,s: AnsiString;

begin

  ss := 'abcdefg';



  s := AnsiLeftStr(ss, 2);

  ShowMessage(s); {ab}



  s := AnsiRightStr(ss, 2);

  ShowMessage(s); {fg}

end;


 
   
// : AnsiMidStr var ss,s: AnsiString; begin ss := 'abcdefg'; s := AnsiMidStr(ss,3,2); ShowMessage(s); {cd} s := AnsiMidStr(ss,3,20); ShowMessage(s); {cdefg} end;
// : AnsiContainsStr、AnsiContainsText var ss,s: AnsiString; b: Boolean; begin ss := 'Hello World'; s := 'hello'; b := AnsiContainsStr(ss,s); { } ShowMessage(BoolToStr(b)); {False} b := AnsiContainsText(ss,s); { } ShowMessage(BoolToStr(b)); {True} end;
// : AnsiStartsStr、AnsiStartsText var ss,s: AnsiString; b: Boolean; begin ss := 'Hello World'; s := 'he'; b := AnsiStartsStr(s,ss); { } ShowMessage(BoolToStr(b)); {False} b := AnsiStartsText(s,ss); { } ShowMessage(BoolToStr(b)); {True} end;
// : AnsiEndsStr、AnsiEndsText var ss,s: AnsiString; b: Boolean; begin ss := 'Hello World'; s := 'ORLD'; b := AnsiEndsStr(s,ss); { } ShowMessage(BoolToStr(b)); {False} b := AnsiEndsText(s,ss); { } ShowMessage(BoolToStr(b)); {True} end;
// : AnsiReplaceStr、AnsiReplaceText var ss,strForm,strTo: AnsiString; begin ss := 'Hello World Hello World'; strForm := 'hello'; strTo := '*'; ss := AnsiReplaceStr(ss, strForm, strTo); { } ShowMessage(ss); {Hello World Hello World} ss := AnsiReplaceText(ss, strForm, strTo); { } ShowMessage(ss); {* World * World} end;
// : AnsiResemblesText var b: Boolean; begin b := AnsiResemblesText('abc','apc'); ShowMessage(BoolToStr(b)); {True } { ? , } end;
// : AnsiReverseString var s: AnsiString; begin s := 'Hello'; s := AnsiReverseString(s); ShowMessage(s); {olleH} end;
// : AnsiMatchStr、AnsiMatchText var arr: array[0..3] of string; s: AnsiString; b: Boolean; begin arr[0] := 'aaa'; arr[1] := 'bbb'; arr[2] := 'ccc'; arr[3] := 'ddd'; s := 'CCC'; b := AnsiMatchStr(s,arr); { } ShowMessage(BoolToStr(b)); {False} b := AnsiMatchText(s,arr); { } ShowMessage(BoolToStr(b)); {True} end;
// : AnsiIndexStr、AnsiIndexText var arr: array[0..3] of string; s: AnsiString; i: Integer; begin arr[0] := 'aaa'; arr[1] := 'bbb'; arr[2] := 'ccc'; arr[3] := 'ddd'; s := 'CCC'; i := AnsiIndexStr(s,arr); { } ShowMessage(IntToStr(i)); {-1, -1 } i := AnsiIndexText(s,arr); { } ShowMessage(IntToStr(i)); {2} end;
// , PosEx var ss,s: string; i: Integer; begin ss := 'CodeGear Delphi 2007'; s := 'Gear'; i := PosEx(s,ss,4); ShowMessage(IntToStr(i)); //5 end;

좋은 웹페이지 즐겨찾기