Unit StrUtils

*****************************************************} { } { Delphi VCL Extensions (RX) } { Copyright (c) 1995, 1996 AO ROSNO } { Copyright (c) 1997, 1998 Master-Bank } { } { This unit based on AlexGraf String Library } { by Alexei Lukin (c) 1992 } { } {

Classes

Functions

AddChar - MakeStr return a string of length N filled with character C.
AddCharR - AddChar return a string left-padded to length N with characters C.
AnsiProperCase - Copy2SpaceDel returns a substring of a string S from begining to first white space and removes this substring from S.
CenterStr - RightStr return a string left-padded to length N with blanks.
CompStr - CenterStr centers the characters in the string based upon the Len specified.
Copy2Space - Copy2SymbDel returns a substring of a string S from begining to first character Symb and removes this substring from S.
Copy2SpaceDel - Copy2Symb returns a substring of a string S from begining to first white space.
Copy2Symb - CompStr compares S1 to S2, with case-sensitivity.
Copy2SymbDel - Copy2Symb returns a substring of a string S from begining to first character Symb.
D2H -
Dec2Hex - Numb2USA converts numeric string S to USA-format.
Dec2Numb - Hex2Dec converts the given hexadecimal string to the corresponding integer value.
DelBSpace - DelChars return a string with all Chr characters removed.
DelChars - DelSpace return a string with all white spaces removed.
DelESpace - DelBSpace trims leading spaces from the given string.
DelRSpace - DelESpace trims trailing spaces from the given string.
DelSpace - Returns string with every occurrence of Srch string replaced with Replace string.
DelSpace1 - DelRSpace trims leading and trailing spaces from the given string.
ExtractDelimited - add the I'th character to result
ExtractQuotedString - QuotedString returns the given string as a quoted string, using the provided Quote character.
ExtractSubstr - ExtractWord, ExtractWordPos and ExtractDelimited given a set of word delimiters, return the N'th word in S.
ExtractWord - Given a set of word delimiters, return start position of N'th word in S.
ExtractWordPos - add the I'th character to result
FindPart - ExtractQuotedString removes the Quote characters from the beginning and end of a quoted string, and reduces pairs of Quote characters within the quoted string to a single character.
H2D -
Hex2Dec - Dec2Hex converts the given value to a hexadecimal string representation with the minimum number of digits (A) specified.
IntToBin - Numb2Dec converts the given B-based numeric string to the corresponding integer value.
IntToRoman - IntToBin converts the given value to a binary string representation with the minimum number of digits specified.
IsEmptyStr - OemToAnsiStr translates a string from the OEM character set into the Windows character set.
IsWild - FindPart compares a string with '?' and another, returns the position of HelpWilds in InputStr.
IsWordPresent - ExtractSubstr given a set of word delimiters, return the substring from S, that started from position Pos.
LeftStr - AddCharR return a string right-padded to length N with characters C.
MakeStr - NPos searches for a N-th position of substring C in a given string.
MS -
NPos - Tab2Space converts any tabulation character in the given string to the Numb spaces characters.
Numb2Dec - Dec2Numb converts the given value to a string representation with the base equal to B and with the minimum number of digits (A) specified.
Numb2USA - IsWild compare InputString with WildCard string and return True if corresponds.
OemToAnsiStr - StrToOem translates a string from the Windows character set into the OEM character set.
QuotedString - IsWordPresent given a set of word delimiters, return True if word W is present in string S.
ReplaceStr - EmptyStr returns true if the given string contains only character from the EmptyChars.
RightStr - LeftStr return a string right-padded to length N with blanks.
RomanToInt - IntToRoman converts the given value to a roman numeric string representation.
StrToOem - ** Common string handling routines **
Tab2Space - DelSpace1 return a string with all non-single white spaces removed.
WordCount - Returns string, with the first letter of each word in uppercase, all other letters in lowercase.
WordPosition - WordCount given a set of word delimiters, return number of words in S.

Types

TCharSet

Constants

Brackets
DigitChars
StdWordDelims

Variables


Functions


function AddChar(C: Char; const S: string; N: Integer): string;

MakeStr return a string of length N filled with character C.

function AddCharR(C: Char; const S: string; N: Integer): string;

AddChar return a string left-padded to length N with characters C.

function AnsiProperCase(const S: string; const WordDelims: TCharSet): string;

Copy2SpaceDel returns a substring of a string S from begining to first white space and removes this substring from S.

function CenterStr(const S: string; Len: Integer): string;

RightStr return a string left-padded to length N with blanks.

function CompStr(const S1, S2: string): Integer;

CenterStr centers the characters in the string based upon the Len specified.

function Copy2Space(const S: string): string;

Copy2SymbDel returns a substring of a string S from begining to first character Symb and removes this substring from S.

function Copy2SpaceDel(var S: string): string;

Copy2Symb returns a substring of a string S from begining to first white space.

function Copy2Symb(const S: string; Symb: Char): string;

CompStr compares S1 to S2, with case-sensitivity. The return value is -1 if S1 < S2, 0 if S1 = S2, or 1 if S1 > S2.

function Copy2SymbDel(var S: string; Symb: Char): string;

Copy2Symb returns a substring of a string S from begining to first character Symb.

function D2H(N: Longint; A: Byte): string;


function Dec2Hex(N: Longint; A: Byte): string;

Numb2USA converts numeric string S to USA-format.

function Dec2Numb(N: Longint; A, B: Byte): string;

Hex2Dec converts the given hexadecimal string to the corresponding integer value.

function DelBSpace(const S: string): string;

DelChars return a string with all Chr characters removed.

function DelChars(const S: string; Chr: Char): string;

DelSpace return a string with all white spaces removed.

function DelESpace(const S: string): string;

DelBSpace trims leading spaces from the given string.

function DelRSpace(const S: string): string;

DelESpace trims trailing spaces from the given string.

function DelSpace(const S: string): string;

Returns string with every occurrence of Srch string replaced with Replace string.

function DelSpace1(const S: string): string;

DelRSpace trims leading and trailing spaces from the given string.

function ExtractDelimited(N: Integer; const S: string; const Delims: TCharSet): string;

add the I'th character to result

function ExtractQuotedString(const S: string; Quote: Char): string;

QuotedString returns the given string as a quoted string, using the provided Quote character.

function ExtractSubstr(const S: string; var Pos: Integer; const Delims: TCharSet): string;

ExtractWord, ExtractWordPos and ExtractDelimited given a set of word delimiters, return the N'th word in S.

function ExtractWord(N: Integer; const S: string; const WordDelims: TCharSet): string;

Given a set of word delimiters, return start position of N'th word in S.

if not finished, find the end of the current word


function ExtractWordPos(N: Integer; const S: string; const WordDelims: TCharSet; var Pos: Integer): string;

add the I'th character to result

function FindPart(const HelpWilds, InputStr: string): Integer;

ExtractQuotedString removes the Quote characters from the beginning and end of a quoted string, and reduces pairs of Quote characters within the quoted string to a single character.

function H2D(const S: string): Longint;


function Hex2Dec(const S: string): Longint;

Dec2Hex converts the given value to a hexadecimal string representation with the minimum number of digits (A) specified.

function IntToBin(Value: Longint; Digits, Spaces: Integer): string;

Numb2Dec converts the given B-based numeric string to the corresponding integer value.

function IntToRoman(Value: Longint): string;

IntToBin converts the given value to a binary string representation with the minimum number of digits specified.

function IsEmptyStr(const S: string; const EmptyChars: TCharSet): Boolean;

OemToAnsiStr translates a string from the OEM character set into the Windows character set.

function IsWild(InputStr, Wilds: string; IgnoreCase: Boolean): Boolean;

FindPart compares a string with '?' and another, returns the position of HelpWilds in InputStr.

now move HelpWilds over InputStr


function IsWordPresent(const W, S: string; const WordDelims: TCharSet): Boolean;

ExtractSubstr given a set of word delimiters, return the substring from S, that started from position Pos.

function LeftStr(const S: string; N: Integer): string;

AddCharR return a string right-padded to length N with characters C.

function MakeStr(C: Char; N: Integer): string;

NPos searches for a N-th position of substring C in a given string.

function MS(C: Char; N: Integer): string;


function NPos(const C: string; S: string; N: Integer): Integer;

Tab2Space converts any tabulation character in the given string to the Numb spaces characters.

function Numb2Dec(S: string; B: Byte): Longint;

Dec2Numb converts the given value to a string representation with the base equal to B and with the minimum number of digits (A) specified.

function Numb2USA(const S: string): string;

IsWild compare InputString with WildCard string and return True if corresponds. } { ** Numeric string handling routines **

function OemToAnsiStr(const OemStr: string): string;

StrToOem translates a string from the Windows character set into the OEM character set.

function QuotedString(const S: string; Quote: Char): string;

IsWordPresent given a set of word delimiters, return True if word W is present in string S.

C++Builder or Delphi 3.0 } {$DEFINE MBCS} {$ENDIF} {$ENDIF


function ReplaceStr(const S, Srch, Replace: string): string;

EmptyStr returns true if the given string contains only character from the EmptyChars.

function RightStr(const S: string; N: Integer): string;

LeftStr return a string right-padded to length N with blanks.

function RomanToInt(const S: string): Longint;

IntToRoman converts the given value to a roman numeric string representation.

function StrToOem(const AnsiStr: string): string;

** Common string handling routines **

function Tab2Space(const S: string; Numb: Byte): string;

DelSpace1 return a string with all non-single white spaces removed.

function WordCount(const S: string; const WordDelims: TCharSet): Integer;

Returns string, with the first letter of each word in uppercase, all other letters in lowercase. Words are delimited by WordDelims.

function WordPosition(const N: Integer; const S: string; const WordDelims: TCharSet): Integer;

WordCount given a set of word delimiters, return number of words in S.

Types


TCharSet = Set of Char

Constants

Brackets = ['(',')','[',']','{','}']

DigitChars = ['0'..'9']

RomanToInt converts the given string to an integer value. If the string doesn't contain a valid roman numeric value, the 0 value is returned.

StdWordDelims = [#0..' ',',','.',';','/','\',':','''','"','`'] + Brackets


Variables