Delphi TStringHelper用法详解
(2013-08-27 22:45:42)
标签:
delphi_xe5it |
分类: Delphi |
Delphi XE4的TStringHelper,对操作字符串进一步带来更多的方法,使用这些方法才可以实现跨平台的代码。
System.SysUtils.TStringHelper
大小写转换:
--------------------------------------------------------------------------------
functionToLower: string;
functionToLower(LocaleID: TLocaleID): string;
functionToLowerInvariant: string;
functionToUpper: string;
functionToUpper(LocaleID: TLocaleID): string;
functionToUpperInvariant: string;
classfunction LowerCase(const S: string): string;
classfunction LowerCase(const S: string; LocaleOptions: TLocaleOptions): string;
classfunction UpperCase(const S: string): string;
classfunction UpperCase(const S: string; LocaleOptions: TLocaleOptions): string;
//--------------------------------------------------------------------------------
var
str: string;
begin
str := 'Delphi';
str := str.ToLower; // delphi
str := str.ToUpper; // DELPHI
end;
--------------------------------------------------------------------------------
清除两边空格或指定字符:
--------------------------------------------------------------------------------
functionTrim: string;
functionTrimLeft: string;
functionTrimRight: string;
functionTrim(const TrimChars: array of Char): string;
functionTrimLeft(const TrimChars: array of Char): string;
functionTrimRight(const TrimChars: array of Char): string;
//--------------------------------------------------------------------------------
var
str1, str2: string;
begin
str1 := ' Delphi 10000 ';
str2 := str1.TrimLeft; // 'Delphi 10000 '
str2 := str1.TrimRight; // ' Delphi 10000'
str2 := str1.Trim; // 'Delphi 10000'
str2 := str1.Trim([' ', '0']); // 'Delphi 1'
end;
--------------------------------------------------------------------------------
字符串对比:
--------------------------------------------------------------------------------
functionCompareTo(const strB: string): Integer;
classfunction Compare(const StrA: string; const StrB: string): Integer;
classfunction CompareText(const StrA: string; const StrB: string): Integer;
classfunction Compare(const StrA: string; const StrB: string; LocaleID: TLocaleID): Integer;
classfunction Compare(const StrA: string; const StrB: string; IgnoreCase: Boolean): Integer;
classfunction Compare(const StrA: string; const StrB: string; IgnoreCase: Boolean; LocaleID: TLocaleID): Integer;
classfunction Compare(const StrA: string; IndexA: Integer; const StrB: string; IndexB: Integer; Length: Integer): Integer;
classfunction Compare(const StrA: string; IndexA: Integer; const StrB: string; IndexB: Integer; Length: Integer; LocaleID: TLocaleID): Integer;
classfunction Compare(const StrA: string; IndexA: Integer; const StrB: string; IndexB: Integer; Length: Integer; IgnoreCase: Boolean): Integer;
classfunction Compare(const StrA: string; IndexA: Integer; const StrB:
System.SysUtils.TStringHelper
大小写转换:
--------------------------------------------------------------------------------
function
function
function
function
function
function
class
class
class
class
//--------------------------------------------------------------------------------
var
begin
end;
--------------------------------------------------------------------------------
清除两边空格或指定字符:
--------------------------------------------------------------------------------
function
function
function
function
function
function
//--------------------------------------------------------------------------------
var
begin
end;
--------------------------------------------------------------------------------
字符串对比:
--------------------------------------------------------------------------------
function
class
class
class
class
class
class
class
class
class