首页 > 代码库 > Delphi XE6 TStringHelper中的string类型转换

Delphi XE6 TStringHelper中的string类型转换

类型转换:


function ToBoolean: Boolean;
function ToInteger: Integer;
function ToSingle: Single;
function ToDouble: Double;
function ToExtended: Extended;

class function ToBoolean(const S: string): Boolean;
class function ToInteger(const S: string): Integer;
class function ToSingle(const S: string): Single;
class function ToDouble(const S: string): Double;
class function ToExtended(const S: string): Extended;

class function Parse(const Value: Integer): string;
class function Parse(const Value: Int64): string;
class function Parse(const Value: Boolean): string;
class function Parse(const Value: Extended): string;
//--------------------------------------------------------------------------------
var
  S: string;
  str: string;
  n: Integer;
  b: Boolean;
  f: Double;
begin
  str := S.Parse(123);
  n := str.ToInteger;  // 123
  b := str.ToBoolean;  // True

  str := S.Parse(True);
  b := str.ToBoolean;  // True
  n := str.ToInteger;  // -1

  str := S.Parse(3.14159260000);
  f := str.ToDouble;  //3.1415926
end;