Code:
interface
uses Classes,
Windows;
type
TrimTStringsMode = (trsTrim, trsLeft, trsRight, trsTop, trsBottom,
trsEmptyLines);
TrimTStringsModes = set of TrimTStringsMode;
// Any combination of the following values can be used as "Modes":
// trsTrim: executes a "Trim" on every string in the stringlist
// trsLeft: executes a "TrimLeft" on every string in the stringlist
// trsRight: executes a "TrimRight" on every string in the stringlist
// trsTop: deletes all empty strings (after trimming) at the top of the TStringList
// trsBottom: deletes all empty strings (after trimming) at the bottom of the TStringList
// trsEmptyLines: deletes all empty strings (after trimming)
CenterMode = (cmLeft, cmMid, cmRight);
TRcsStrings = class(TStringList)
private
public
constructor Create;
destructor Destroy; override;
procedure LoadFromFileInclude(Filename: string);
procedure AddFromFileInclude(FileName: string);
function ToCSV: string;
procedure FromCSV(const CSV: string);
function ToString(const Separator: Char = ','): string;
procedure FromString(const S: string; const Separator: Char = ',');
procedure TrimStrings(const Modes: TrimTStringsModes = [trsTrim]);
end;
function CompareKeys(KeysA: array of string; KeysB: array of string): integer; overload;
// First KeysA[0] is compared with KeysB[0]; if they are the same then
// KeysA[1] is compared with KeysB[1].. until a difference is encountered
// or the last string in each "keys" is processed.
// The function returns
// zero if both key groups are entirely the same (A=B),
// +1 if A > B, or -1 if B > A
function CompareKeys(KeysA: TStrings; KeysB: TStrings): integer; overload;
// See above function
function TStringsToCSV(T: TStrings): string;
// Returns a "comma separated value" string with stringlist "T" as contents
procedure CSVToTStrings(const CSV: string; T: TStrings);
// Converts a "comma separated value" string into in stringlist "T"
function ShortenedString(S: string; const L: Integer): string;
// Returns S if length(S) <= L; else S is returned shortened with dots (3) in the middle; the
// total length of the returned string is then L
function QuotedString(S: string; const Conditionally: Boolean = false): string;
// Returns S with leading and trailing double quotes added. If Conditionally is true,
// the double quotes are added only if the string contains spaces or is empty.
function UnquotedString(S: string): string;
// Returns S without its leading and trailing double quotes.
function MakeCommandLine(const Cmds: array of string): string;
// Makes a command line out of the command and parameters in "Cmds":
// surrounds command and parameters which contain spaces with double quotes
function ExcludeTrailingCrLf(S: string): string;
// Removes the trailing CR or LF or CRLF sequence at the end of a string
// after "Right" trimming first.
procedure StringToTStrings(const S: string; T: TStrings; const Separator: Char = ',');
// StringToTStrings converts a separator delimited string into a Stringlist
function TStringsToString(T: TStrings; const Separator: Char = ','): string;
// TStringsToString converts a Stringlist into a separator delimited string
procedure TrimTStrings(T: TStrings; const Modes: TrimTStringsModes = [trsTrim]);
// see type "TrimTStringsModes" above
function BeginString(Source: string; const P: Integer): string; overload;
// BeginString returns the part (of Source) left of position P
function BeginString(Source, Tag: string): string; overload;
// BeginString returns the part (of Source) before the Tag
// If the Tag is not found, an empty string is returned
// Only the first occurance of Tag in Source is taken into account
function EndString(Source: string; const P: Integer): string; overload;
// EndString returns the part (of Source) from position P onwards (the character on
// position P included
function EndString(Source, Tag: string): string; overload;
// EndString returns the part (of Source) after the Tag
// If the Tag is not found, an empty string is returned
// Only the first occurance of Tag in Source is taken into account
procedure SplitString(Source: string; const P: Integer; var Left, Right:
string); overload;
// Returns in Left and Right respectively the "BeginString" and the "EndString"
// See the two functions above
procedure SplitString(Source: string; const Tag: string; var Left, Right:
string);
overload;
// Returns in Left and Right respectively the "BeginString" and the "EndString"
// See the two functions above
function CopyString(Source: string; const Start, Stop: Integer): string;
overload;
// Returns the part of Source from position Start to Position Stop, the characters on
// both positions included
function CopyString(Source: string; const Tag1, Tag2: string): string;
overload;
// Returns the part of the Source between Tag1 and Tag2
function DeleteString(Source: string; const Start, Stop: Integer): string;
overload;
// Returns the Source with the part deleted from the Start to and including the Stop position
function DeleteString(Source, Tag1, Tag2: string; const All: Boolean =
false): string; overload;
// Returns Source with the text between the 2 tags deleted (also the tags
// themselves are deleted). If "All" is true, then all occurances are deleted, if false only
// the first one is deleted. If Tag1 or Tag2 is not present, the Source is returned unchanged
procedure DeleteStringProc(var Source: string; const Start, Stop: Integer);
overload;
// Returns the Source with the part deleted from the Start to and including the Stop position
procedure DeleteStringProc(var Source: string; const Tag1, Tag2: string; const All:
Boolean =
false); overload;
// Returns Source with the text between the 2 tags deleted (also the tags
// themselves are deleted). If "All" is true, then all occurances are deleted, if false only
// the first one is deleted. If Tag1 or Tag2 is not present, the Source is returned unchanged
type
TPosNSkipTable = array[Char] of Integer;
function PosN(const SubStr, Source: string; const P: Integer = 1): Integer; overload;
// Same as the "Pos" function, but the search starts at position P (1.. length(Source))
function PosN(const SubStr, Source: string; const Stable: TPosNSkipTable; const P:
Integer = 1): Integer; overload;
// Same as the "PosN" function but with an external SkipTable passed as parameter
// Execute "PosNInit" (see below) to create the skiptable before calling this function!
procedure PosNInit(var Table: TPosNSkipTable; const SubStr: string);
// Initialises the PosNSkipTable before usage of the above version of PosN
procedure FillString(const SubString: string; var S: string; Position: Word);
// Fillstring returns "S" with "SubString" at place "Position" in it.
// The original characters as Position "Position" in "S" are overwritten.
// The Length of the string "S" is adapted if necessary.
function CenterString(S: string; const Mode: CenterMode; const Len: Word): string;
// Centerstring returns "S" placed in a string of Length "Len" at the
// place (cmLeft, cmMiddle or cmRight) defined by "CenterMode"
function SpaceString(const Len: Word): string;
// SpaceString returns a string of Length "Len" containing all spaces
function DayMonthYearString: string;
// DayMonthYearString returns a string containing the date of today in the
// format: dd-mm-yy (e.g. 20-12-49 for Dec 20th 1949)
function YYMMDDString: string;
// YYMMDDString returns a string containing the date of today in the
// format: yymmdd (e.g. 491220 for Dec 20th 1949)
function YYYYMMDDString: string;
// YYYYMMDDString returns a string containing the date of today in the
// format: yyyymmdd (e.g. 19491220 for Dec 20th 1949)
function TimeString: string; {hr:min:sec}
// TimeString rerurns the current time in the
// format: hh:mm:ss (e.g. 23:50:55 for 23 hrs, 50 minutes and 55 secs)
function IntString(const I: Longint; const Len: Byte): string;
// IntString returns a string of Length "Len",
// representing "I" right aligned
function StringIsIn(S1, S2: string; const Separator: Char = ','): Boolean;
// StringIsIn returns true if S1 is in the "Separator separated" strings in S2
function BinString(const B: Byte): string;
// BinString returns a string with the binary representation of "B".
// The two nibbles are separated with an underscore
function LeftPad(const S: string; Len: integer; Ch: Char = ' '): string;
// Generates a string consisting of "S" left padded with characters "Ch"
// till length "Len" is reached.
function RightPad(const S: string; Len: integer; Ch: Char = ' '): string;
// Generates a string consisting of "S" right padded with characters "Ch"
// till length "Len" is reached.
function FloatToString(const V: Real): string;
// FloatToString converts the floating-point value given by V to its string representation.
// The conversion uses general number format with 15 significant digits.
// The scientific notation ("E") is never used.
function IsNumber(S: string): boolean;
// IsNumeric checks if S is a valid number (allows floating point non scientific notation)
function DateToWeekNo(Dat: string): string;
// Returns the weeknumber of date Dat. The format of the result is "yymm.d".
// "d" is the number of the day, 1 = monday
// only valid from year 2000 till 2099
function WeekNoToDate(WeekNo: string): string;
// Returns the date corresponding to the weeknumber "WeekNo"
// only valid from year 2000 till 2099
Bookmarks