⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d_str32.pas

📁 Motorola 集群通信系统中SDTS车载台PEI端测试程序
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  ch := UpCase(ch);
  for n := 0 to 15 do begin
    if ch = Digits[n] then
      b := n;
  end;
  if b < 16 then
    HexChar2Byte := true
  else
    HexChar2Byte := false;
end;

function HexChr2Byte(ch : char): byte;
var
  n : byte;
begin
  HexChr2Byte := 16;
  ch := UpCase(ch);
  for n := 0 to 15 do begin
    if ch = Digits[n] then
      HexChr2Byte := n;
  end;
end;

function HexB(B : Byte) : string;
  {-Return hex string for byte}
begin
  SetLength(Result,2);
  HexB[1] := Digits[B shr 4];
  HexB[2] := Digits[B and $F];
end;

function HexChar(B : byte) : Char;
  {-Return hex Char for byte}
begin
  HexChar := Digits[B and $F];
end;

function HexW(W : Word) : string;
  {-Return hex string for word}
begin
  SetLength(Result,4);
  HexW[1] := Digits[hi(W) shr 4];
  HexW[2] := Digits[hi(W) and $F];
  HexW[3] := Digits[lo(W) shr 4];
  HexW[4] := Digits[lo(W) and $F];
end;

function HexL(L : LongInt) : string;
  {-Return hex string for LongInt}
begin
  with Long(L) do
    HexL := HexW(HighWord)+HexW(LowWord);
end;

function Str2Int(S : string; var I : Integer) : Boolean;
  {-Convert a string to an integer, returning true if successful}
begin
  Result := TRUE;
  try
    I := SysUtils.StrToInt(s);
  except
    Result := FALSE;
  end;
end;

function Str2ShortInt(S : string; var I : ShortInt) : Boolean;
  {-Convert a string to a ShortInteger, returning true if successful}
var
  code : integer;
begin
  while S[Length(s)] = ' ' do
    Delete(s,Length(s),1);
  Val(S, I, code);
  if code <> 0 then begin
    I := code;
    Str2ShortInt := False;
  end else
    Str2ShortInt := True;
end;

function Str2Word(S : string; var I : Word) : Boolean;
  {-Convert a string to a word, returning true if successful}
var
  code : integer;
begin
  while S[Length(s)] = ' ' do
    Delete(s,Length(s),1);
  Val(S, I, code);
  if code <> 0 then begin
    I := code;
    Str2Word := False;
  end else
    Str2Word := True;
end;

function HexStr2Word(S : string; var I : Word) : Boolean;
  {-Convert a hexstring to a word, returning true if successful}
var
  code,n : integer;
begin
  code := 0;
  I := 0;
  while S[Length(s)] = ' ' do
    Delete(s,Length(s),1);
  for n := 1 to Length(s) do begin
    case UpCase(S[n]) of
      '0' : I := 0 + I SHL 4;
      '1' : I := 1 + I SHL 4;
      '2' : I := 2 + I SHL 4;
      '3' : I := 3 + I SHL 4;
      '4' : I := 4 + I SHL 4;
      '5' : I := 5 + I SHL 4;
      '6' : I := 6 + I SHL 4;
      '7' : I := 7 + I SHL 4;
      '8' : I := 8 + I SHL 4;
      '9' : I := 9 + I SHL 4;
      'A' : I := 10 + I SHL 4;
      'B' : I := 11 + I SHL 4;
      'C' : I := 12 + I SHL 4;
      'D' : I := 13 + I SHL 4;
      'E' : I := 14 + I SHL 4;
      'F' : I := 15 + I SHL 4;
      else
        code := 1;
    end;
  end;
  if code <> 0 then begin
    I := code;
    HexStr2Word := False;
  end else
    HexStr2Word := True;
end;

function Str2Byte(S : string; var I : Byte) : Boolean;
  {-Convert a string to a byte, returning true if successful}
var
  code : Integer;
begin
  while S[Length(s)] = ' ' do
    Delete(s,Length(s),1);
  Val(S, I, code);
  if code <> 0 then begin
    I := code;
    Str2Byte := False;
  end else
    Str2Byte := True;
end;

function Str2Long(S : string; var I : LongInt) : Boolean;
  {-Convert a string to a longint, returning true if successful}
var
  code : integer;
begin
  while S[Length(s)] = ' ' do
    Delete(s,Length(s),1);
  Val(S, I, code);
  if code <> 0 then begin
    I := code;
    Str2Long := False;
  end else
    Str2Long := True;
end;

function Str2Real(S : string; var R : Real) : Boolean;
  {-Convert a string to a real, returning true if successful}
var
  Code : integer;
begin
  while S[Length(s)] = ' ' do
    Delete(s,Length(s),1);

  if s = '' then begin
    Result := False;
    Exit;
  end;

  Val(S, R, Code);
  if Code <> 0 then begin
    R := Code;
    Str2Real := False;
  end else
    Str2Real := True;
end;

function Str2Float(S : string; var F : Float) : Boolean;
  {-Convert a string to a float, returning true if successful}
var
  Code : integer;
begin
  while S[Length(s)] = ' ' do
    Delete(s,Length(s),1);

  Val(S, F, Code);
  if Code <> 0 then begin
    F := Code;
    Str2Float := False;
  end else
    Str2Float := True;
end;

function Long2Str(L : LongInt) : string;
  {-Convert a long/word/integer/byte/shortint to a string}
var
  S : string;
begin
  Str(L, S);
  Long2Str := S;
end;

function Real2Str(R : Float; Width, Places : Byte) : string;
  {-Convert a real to a string}
var
  S : string;
begin
  Str(R:Width:Places, S);
  Real2Str := S;
end;
function Pad(S : string; Len : Byte) : string;
  {-Return a string right-padded to length len with blanks}
var
  n,m : integer;
begin
  if Length(s) > Len then
    Result := s
  else begin
    Result := s;
    n := Len - Length(s);
    for m := 1 to n do
      result := Result + ' ';
  end;
end;


function PadChar(S : string; Len : Byte; ch : char) : string;
  {-Return a string right-Padded to length len with ch}
var
  n,m : integer;
begin
  if Length(s) > Len then
    Result := s
  else begin
    Result := s;
    n := Len - Length(s);
    for m := 1 to n do
      result := Result + ch;
  end;
end;


function Cut(S : string; Len : Byte) : string;
  {-Return a string truncated to length len}
begin
  if Length(s) > Len then
    Cut := copy(s,1,Len)
  else
    Cut := S;
end;

function LeftPad(S : string; Len : Byte) : string;
  {-Return a string left-padded to length len with blanks}
var
  n,m : integer;
begin
  if Length(s) > Len then
    Result := s
  else begin
    Result := s;
    n := Len - Length(s);
    for m := 1 to n do
      result := ' ' + Result;
  end;
end;

function LeftPadChar(S : string; Len : Byte; ch : char) : string;
  {-Return a string left-padded to length len with ch}
var
  n,m : integer;
begin
  if Length(s) > Len then
    Result := s
  else begin
    Result := s;
    n := Len - Length(s);
    for m := 1 to n do
      result := ch + Result;
  end;
end;

function Left2Pad(S : string; Len : Byte) : string;
  {-Return a string left-padded to length len with Double blanks}
var
  n,m : integer;
begin
  if Length(s) > Len then
    Result := s
  else begin
    Result := s;
    n := Len - Length(s);
    for m := 1 to n do
      result := '  ' + Result;
  end;
end;

function TrimLead(S : string) : string;
  {-Return a string with leading white space removed}
var
  I : Word;
begin
  I := 1;
  while (I <= Length(S)) and (S[I] <= ' ') do
    Inc(I);
  Dec(I);
  if I > 0 then
    Delete(S, 1, I);
  TrimLead := S;
end;

function TrimTrail(S : string) : string;
  {-Return a string with trailing white space removed}
var
  SLen : Byte absolute S;
begin
  while (SLen > 0) and (S[SLen] <= ' ') do
    Dec(SLen);
  TrimTrail := S;
end;

function Trim(S : string) : string;
  {-Return a string with leading and trailing white space removed}
begin
  result := SysUtils.Trim(s);
end;

function  FileExists(s : PChar) : boolean;
var
  F : file of byte;
begin
  if StrLen(s) = 0 then begin
    FileExists := False;
    Exit;
  end;
  Assign(F, s);
  {$I-}
  Reset(F);
  {$I+}
  if IOResult = 0 then begin
    FileExists := True;
    Close(f);
  end
  else
    FileExists := False;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -