//对比字符串是不是一样: AnsiSameStr、AnsiSameText var ss,s: AnsiString; b: Boolean; begin ss := 'abc'; s := 'ABC'; b := AnsiSameStr(ss,s); {区分大小写} ShowMessage(BoolToStr(b)); {False} b := AnsiSameText(ss,s); {不区分大小写} ShowMessage(BoolToStr(b)); {True} end; //比较两个字符串大小: AnsiCompareStr、AnsiCompareText var s1,s2: AnsiString; i: Integer; begin s1 := 'Hello'; s2 := 'hello'; i := AnsiCompareStr(s1,s2); {区分大小写} ShowMessage(IntToStr(i)); {1} i := AnsiCompareText(s1,s2); {不区分大小写} ShowMessage(IntToStr(i)); {0} {有 3 种可能的返回值: s1 > s2 : 1 s1 < s2 : -1 s1 = s2 : 0 } end; //比较两个文件名大小: AnsiCompareFileName var s1,s2: AnsiString; i: Integer; begin s1 := 'c:\temp\2.txt'; s2 := 'c:\temp\1.TXT'; i := AnsiCompareFileName(s1,s2); ShowMessage(IntToStr(i)); {1} {有 3 种可能的返回值: s1 > s2 : 1 s1 < s2 : -1 s1 = s2 : 0 } end; //大小写转换: AnsiUpperCase、AnsiLowerCase var ss,s: AnsiString; begin ss := 'Hello'; s := AnsiUpperCase(ss); ShowMessage(s); {HELLO} s := AnsiLowerCase(ss); ShowMessage(s); {hello} end; //文件名大小写转换: AnsiUpperCaseFileName、AnsiLowerCaseFileName var ss,s: AnsiString; begin ss := 'C:\Temp\1.txt'; s := AnsiUpperCaseFileName(ss); ShowMessage(s); {C:\TEMP\1.TXT} s := AnsiLowerCaseFileName(ss); ShowMessage(s); {c:\temp\1.txt} end; //查找一个字符串在另一个字符串中最先出现的位置: AnsiPos var ss,s: AnsiString; i: Integer; begin ss := 'abcdefgcd'; s := 'cd'; i := AnsiPos(s,ss); ShowMessage(IntToStr(i)); {3} end; //添加定界符: AnsiQuotedStr var ss,s: AnsiString; begin ss := 'Hello'; s := AnsiQuotedStr(ss, '"'); {参数2是定界符, Char 类型} ShowMessage(s); {"Hello"} s := AnsiQuotedStr(ss, '#'); ShowMessage(s); {#Hello#} ss := 'Hello#Hello'; {如果中间包含要添加的定界符, 将被双写} s := AnsiQuotedStr(ss, '#'); ShowMessage(s); {#Hello##Hello#} end; //取消字符串两边的定界符: AnsiDequotedStr var ss,s: AnsiString; begin ss := '"Hello"'; s := AnsiDequotedStr(ss, '"'); ShowMessage(s); {Hello} end;
Delphi 中的字符串函数(5) - SysUtils 中的 Ansi 字符串函数
最新推荐文章于 2023-02-09 07:56:05 发布