Skip to content

Commit

Permalink
[+] TStr: CharCount, FirstCharPos, LastCharPos
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdp committed Apr 28, 2020
1 parent 03711e3 commit aceca00
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Base/JPL.TStr.pas
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ TStr = record
class function TrimFromEnd(const s: string; const StringToCut: string): string; static;
class function TrimFromStart(const s: string; const StringToCut: string): string; static;

class function CharCount(const s: string; const AChar: Char): integer; static;
class function FirstCharPos(const s: string; const AChar: Char): integer; static;
class function LastCharPos(const s: string; const AChar: Char): integer; static;

class property DecimalSeparator: Char read GetDecimalSeparator write SetDecimalSeparator;
class property ThousandSeparator: Char read GetThousandSeparator write SetThousandSeparator;
class property DateSeparator: Char read GetDateSeparator write SetDateSeparator;
Expand Down Expand Up @@ -318,6 +322,41 @@ class function TStr.TrimFromStart(const s, StringToCut: string): string;
Result := JPL.Strings.TrimFromStart(s, StringToCut);
end;

class function TStr.CharCount(const s: string; const AChar: Char): integer;
var
i: integer;
begin
Result := 0;
for i := 1 to Length(s) do
if s[i] = AChar then Inc(Result);
end;

class function TStr.FirstCharPos(const s: string; const AChar: Char): integer;
var
i: integer;
begin
Result := 0;
for i := 1 to Length(s) do
if s[i] = AChar then
begin
Result := i;
Break;
end;
end;

class function TStr.LastCharPos(const s: string; const AChar: Char): integer;
var
i: integer;
begin
Result := 0;
for i := Length(s) downto 1 do
if s[i] = AChar then
begin
Result := i;
Break;
end;
end;

class function TStr.GetDecimalSeparator: Char;
begin
{$IFDEF FPC}Result := FormatSettings.DecimalSeparator;{$ENDIF}
Expand Down

0 comments on commit aceca00

Please sign in to comment.