-
Declaration:
- Function AdjustLineBreaks(const S: string): string;
-
Description:
- AdjustLineBreaks will change all #13 characters with #13#10 on WINDOWS NT and DOS.
On LINUX, all #13#10 character pairs are converted to #10 and single #13 characters also.
-
Errors:
- None.
-
See also:
- AnsiCompareStr (762), AnsiCompareText (763)
Listing: sysutex/ex48.pp
-
Declaration:
- Function AnsiCompareStr(const S1, S2: string): integer;
-
Description:
- AnsiCompareStr compares two strings and returns the following result:
-
¡0
- if S1<S2.
-
0
- if S1=S2.
-
¿0
- if S1>S2.
the comparision takes into account Ansi characters, i.e. it takes care of strange accented characters.
Contrary to AnsiCompareText (763), the comparision is case sensitive.
-
Errors:
- None.
-
See also:
- AdjustLineBreaks (762), AnsiCompareText (763)
Listing: sysutex/ex49.pp
-
Declaration:
- Function AnsiCompareText(const S1, S2: string): integer;
-
Description:
-
-
Description:
- AnsiCompareText compares two strings and returns the following result:
-
¡0
- if S1<S2.
-
0
- if S1=S2.
-
¿0
- if S1>S2.
the comparision takes into account Ansi characters, i.e. it takes care of strange accented characters.
Contrary to AnsiCompareStr (762), the comparision is case insensitive.
-
Errors:
- None.
-
See also:
- AdjustLineBreaks (762), AnsiCompareText (763)
Listing: sysutex/ex50.pp
-
Declaration:
- Function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
-
Description:
- AnsiExtractQuotedStr Returns Src as a string, with Quote characters removed from the
beginning and end of the string, and double Quote characters replaced by a single Quote
characters. As such, it revereses the action of AnsiQuotedStr (767).
-
Errors:
- None.
-
See also:
- AnsiQuotedStr (767)
Listing: sysutex/ex51.pp
-
Declaration:
- Function AnsiLastChar(const S: string): PChar;
-
Description:
- This function returns a pointer to the last character of S. Since multibyte characters are
not yet supported, this is the same as @S[Length(S)]).
-
Errors:
- None.
-
See also:
- AnsiStrLastChar (769)
Listing: sysutex/ex52.pp
-
Declaration:
- Function AnsiLowerCase(const s: string): string;
-
Description:
- AnsiLowerCase converts the string S to lowercase characters and returns the resulting
string. It takes into account the operating system language settings when doing this, so spcial
characters are converted correctly as well.
Remark On linux, no language setting is taken in account yet.
-
Errors:
- None.
-
See also:
- AnsiUpperCase (773), AnsiStrLower (772), AnsiStrUpper (773)
Listing: sysutex/ex53.pp
-
Declaration:
- Function AnsiQuotedStr(const S: string; Quote: char): string;
-
Description:
- AnsiQuotedString quotes the string S and returns the result. This means that it puts the
Quote character at both the beginning and end of the string and replaces any occurrence of
Quote in S with 2 Quote characters. The action of AnsiQuotedString can be reversed by
AnsiExtractQuotedStr (765).
-
Errors:
- None.
-
See also:
- AnsiExtractQuotedStr (765)
For an example, see AnsiExtractQuotedStr (765)
-
Declaration:
- Function AnsiStrComp(S1, S2: PChar): integer;
-
Description:
- AnsiStrComp compares 2 PChar strings, and returns the following result:
-
¡0
- if S1<S2.
-
0
- if S1=S2.
-
¿0
- if S1>S2.
The comparision of the two strings is case-sensitive. The function does not yet take
internationalization settings into account.
-
Errors:
- None.
-
See also:
- AnsiCompareText (763), AnsiCompareStr (762)
Listing: sysutex/ex54.pp
-
Declaration:
- Function AnsiStrIComp(S1, S2: PChar): integer;
-
Description:
- AnsiStrIComp compares 2 PChar strings, and returns the following result:
-
¡0
- if S1<S2.
-
0
- if S1=S2.
-
¿0
- if S1>S2.
The comparision of the two strings is case-insensitive. The function does not yet take
internationalization settings into account.
-
Errors:
- None.
-
See also:
- AnsiCompareText (763), AnsiCompareStr (762)
Listing: sysutex/ex55.pp
-
Declaration:
- function AnsiStrLastChar(Str: PChar): PChar;
-
Declaration:
- AnsiStrLastChar returns a pointer to the last character of Str. Since
multibyte characters are not yet supported, this is the same as
StrEnd(Str)-1.
-
Errors:
- None.
-
See also:
- AnsiLastChar (765)
Listing: sysutex/ex58.pp
-
Declaration:
- Function AnsiStrLComp(S1, S2: PChar; MaxLen: cardinal): integer;
-
Description:
- AnsiStrLComp compares the first Maxlen characters of 2 PChar strings, S1 and S2, and returns
the following result:
-
¡0
- if S1<S2.
-
0
- if S1=S2.
-
¿0
- if S1>S2.
The comparision of the two strings is case-sensitive. The function does not yet take
internationalization settings into account.
-
Errors:
- None.
-
See also:
- AnsiCompareText (763), AnsiCompareStr (762)
Listing: sysutex/ex56.pp
-
Declaration:
- Function AnsiStrLIComp(S1, S2: PChar; MaxLen: cardinal): integer;
-
Description:
- AnsiStrLIComp compares the first Maxlen characters of 2 PChar strings, S1 and S2, and returns
the following result:
-
¡0
- if S1<S2.
-
0
- if S1=S2.
-
¿0
- if S1>S2.
The comparision of the two strings is case-insensitive. The function does not yet take
internationalization settings into account.
-
Errors:
- None.
-
See also:
- AnsiCompareText (763), AnsiCompareStr (762)
Listing: sysutex/ex57.pp
-
Declaration:
- Function AnsiStrLower(Str: PChar): PChar;
-
Description:
- AnsiStrLower converts the PChar Str to lowercase characters and returns the resulting
pchar. Note that Str itself is modified, not a copy, as in the case of AnsiLowerCase (766).
It takes into account the operating system language settings when doing this, so spcial
characters are converted correctly as well.
Remark On linux, no language setting is taken in account yet.
-
Errors:
- None.
-
See also:
- AnsiStrUpper (773), AnsiLowerCase (766)
Listing: sysutex/ex59.pp
-
Declaration:
- Function AnsiStrUpper(Str: PChar): PChar;
-
Description:
- AnsiStrUpper converts the PChar Str to uppercase characters and returns the resulting
string. Note that Str itself is modified, not a copy, as in the case of AnsiUpperCase (773).
It takes into account the operating system language settings when doing this, so spcial
characters are converted correctly as well.
Remark On linux, no language setting is taken in account yet.
-
Errors:
- None.
-
See also:
- AnsiUpperCase (773), AnsiStrLower (772), AnsiLowerCase (766)
Listing: sysutex/ex60.pp
-
Declaration:
- Function AnsiUpperCase(const s: string): string;
-
Description:
- AnsiUpperCase converts the string S to uppercase characters and returns the resulting
string. It takes into account the operating system language settings when doing this, so spcial
characters are converted correctly as well.
Remark On linux, no language setting is taken in account yet.
-
Errors:
- None.
-
See also:
- AnsiStrUpper (773), AnsiStrLower (772), AnsiLowerCase (766)
Listing: sysutex/ex61.pp
-
Declaration:
- Procedure AppendStr(var Dest: String; const S: string);
-
Description:
- AppendStr appends S to Dest.
This function is provided for Delphi compatibility only, since it is completely equivalent to
Dest:=Dest+S.
-
Errors:
- None.
-
See also:
- AssignStr (775),NewStr (548), DisposeStr (548)
Listing: sysutex/ex62.pp
-
Declaration:
- Procedure AssignStr(var P: PString; const S: string);
-
Description:
- AssignStr allocates S to P. The old value of P is disposed of.
This function is provided for Delphi compatibility only. AnsiStrings are managed on the
heap and should be preferred to the mechanism of dynamically allocated strings.
-
Errors:
- None.
-
See also:
- NewStr (548), AppendStr (774), DisposeStr (548)
Listing: sysutex/ex63.pp
-
Declaration:
- Function BCDToInt(Value: integer): integer;
-
Description:
- BCDToInt converts a BCD coded integer to a normal integer.
-
Errors:
- None.
-
See also:
- StrToInt (804), IntToStr (796)
Listing: sysutex/ex64.pp
-
Declaration:
- Function CompareMem(P1, P2: Pointer; Length: cardinal): integer;
-
Description:
- CompareMem compares, byte by byte, 2 memory areas pointed to by P1 and P2, for a length
of L bytes.
It returns the following values:
-
¡0
- if at some position the byte at P1 is less than the byte at the same postion at P2.
-
0
- if all L bytes are the same.
-
3
-
Errors:
-
-
See also:
-
Declaration:
- Function CompareStr(const S1, S2: string): Integer;
-
Description:
- CompareStr compares two strings, S1 and S2, and returns the following result:
-
¡0
- if S1<S2.
-
0
- if S1=S2.
-
¿0
- if S1>S2.
The comparision of the two strings is case-sensitive. The function does not take internationalization
settings into account, it simply compares ASCII values.
-
Errors:
- None.
-
See also:
- AnsiCompareText (763), AnsiCompareStr (762), CompareText (778)
Listing: sysutex/ex65.pp
-
Declaration:
- Function CompareText(const S1, S2: string): integer;
-
Description:
- CompareText compares two strings, S1 and S2, and returns the following result:
-
¡0
- if S1<S2.
-
0
- if S1=S2.
-
¿0
- if S1>S2.
The comparision of the two strings is case-insensitive. The function does not take internationalization
settings into account, it simply compares ASCII values.
-
Errors:
- None.
-
See also:
- AnsiCompareText (763), AnsiCompareStr (762), CompareStr (777)
Listing: sysutex/ex66.pp
-
Declaration:
- Procedure DisposeStr(S: PString);
-
Description:
- DisposeStr removes the dynamically allocated string S from the heap, and releases the
occupied memory.
This function is provided for Delphi compatibility only. AnsiStrings are managed on the
heap and should be preferred to the mechanism of dynamically allocated strings.
-
Errors:
- None.
-
See also:
- NewStr (548), AppendStr (774), AssignStr (775)
For an example, see DisposeStr (548).
-
Declaration:
- Function FloatToStr(Value: Extended): String;
-
Description:
- FloatToStr converts the floating point variable Value to a string representation. It will choose
the shortest possible notation of the two following formats:
-
Fixed format
- will represent the string in fixed notation,
-
Decimal format
- will represent the string in scientific notation.
(more information on these formats can be found in FloatToStrF (780)) FloatToStr is completely
equivalent to a FloatToStrF(Value, ffGeneral, 15, 0); call.
-
Errors:
- None.
-
See also:
- FloatToStrF (780), FormatFloat (794), StrToFloat (803)
Listing: sysutex/ex67.pp
-
Declaration:
- Function FloatToStrF(Value: Extended; format: TFloatFormat; Precision,
Digits: Integer): String;
-
Description:
- FloatToStrF converts the floating point number value to a string representation, according
to the settings of the parameters Format, Precision and Digits.
The meaning of the Precision and Digits parameter depends on the Format parameter. The
format is controlled mainly by the Format parameter. It can have one of the following
values:
-
ffcurrency
- Money format. Value is converted to a string using the global variables
CurrencyString, CurrencyFormat and NegCurrencyFormat. The Digits paramater
specifies the number of digits following the decimal point and should be in the range -1
to 18. If Digits equals -1, CurrencyDecimals is assumed. The Precision parameter is
ignored.
-
ffExponent
- Scientific format. Value is converted to a string using scientific notation: 1 digit
before the decimal point, possibly preceded by a minus sign if Value is negative. The
number of digits after the decimal point is controlled by Precision and must lie in the
range 0 to 15.
-
ffFixed
- Fixed point format. Value is converted to a string using fixed point notation. The
result is composed of all digits of the integer part of Value, preceded by a minus sign
if Value is negative. Following the integer part is DecimalSeparator and then the
fractional part of Value, rounded off to Digits numbers. If the number is too large
then the result will be in scientific notation.
-
ffGeneral
- General number format. The argument is converted to a string using ffExponent
or ffFixed format, depending on wich one gives the shortest string. There will be no
trailing zeroes. If Value is less than 0.00001 or if the number of decimals left of the
decimal point is larger than Precision then scientific notation is used, and Digits is
the minimum number of digits in the exponent. Otherwise Digits is ignored.
-
ffnumber
- Is the same as ffFixed, except that thousand separators are inserted in the resultig
string.
-
Errors:
- None.
-
See also:
- FloatToStr (779), FloatToText (782)
Listing: sysutex/ex68.pp
-
Declaration:
- Function FloatToText(Buffer : Pchar;Value: Extended; Format: TFloatFormat;
Precision, Digits: Integer): Longint;
-
Description:
- FloatToText converts the floating point variable Value to a string representation and
stores it in Buffer. The conversion is giverned by format, Precisison and Digits. more
information on these parameters can be found in FloatToStrF (780). Buffer should point to
enough space to hold the result. No checking on this is performed.
The result is the number of characters that was copied in Buffer.
-
Errors:
- None.
-
See also:
- FloatToStr (779), FloatToStrF (780)
Listing: sysutex/ex69.pp
-
Declaration:
- Procedure (Var Res: String; Const Fmt : String; Const args: Array of
const);
-
Description:
- FmtStr calls Format (784) with Fmt and Args as arguments, and stores the result in Res.
For more information on how the resulting string is composed, see Format (784).
-
Errors:
- In case of error, a EConvertError exception is raised.
-
See also:
- Format (784), FormatBuf (793).
Listing: sysutex/ex70.pp
-
Declaration:
- Function Format(Const Fmt : String; const Args : Array of const) : String;
-
Description:
- Format replaces all placeholders inFmt with the arguments passed in Args and returns the
resulting string. A placeholder looks as follows:
'%' [Index':'] ['-'] [Width] ['.' Precision] ArgType
|
elements between single quotes must be typed as shown without the quotes, and elements
between square brackets [ ] are optional. The meaning of the different elements is shown
below:
-
’%’
- starts the placeholder. If you want to insert a literal % character, then you must insert
two of them : %%.
-
Index ’:’
- takes the Index-th element in the argument array as the element to insert.
-
’-’
- tells Format to left-align the inserted text. The default behaviour is to right-align inserted
text. This can only take effect if the Width element is also specified.
-
Width
- the inserted string must have at least have Width characters. If not, the inserted
string will be padded with spaces. By default, the string is left-padded, resulting in a
right-aligned string. This behaviour can be changed by the '-' character.
-
’.’ Precision
- Indicates the precision to be used when converting the argument. The exact
meaning of this parameter depends on ArgType.
The Index, Width and Precision parameters can be replaced by *, in which case their value will
be read from the next element in the Args array. This value must be an integer, or an
EConvertError exception will be raised.
The argument type is determined from ArgType. It can have one of the following values (case
insensitive):
-
D
- Decimal format. The next argument in the Args array should be an integer. The argument
is converted to a decimal string,. If precision is specified, then the string will have at
least Precision digits in it. If needed, the string is (left) padded with zeroes.
-
E
- scientific format. The next argument in the Args array should be a Floating point value. The
argument is converted to a decimal string using scientific notation, using FloatToStrF
(780), where the optional precision is used to specify the total number of decimals.
(defalt a valueof 15 is used). The exponent is formatted using maximally 3 digits.
In short, the E specifier formats it’s arguument as follows:
FloatToStrF(Argument,ffexponent,Precision,3)
|
-
F
- fixed point format. The next argument in the Args array should be a floating point
value. The argument is converted to a decimal string, using fixed notation (see
FloatToStrF (780)). Precision indicates the number of digits following the decimal
point.
In short, the F specifier formats it’s arguument as follows:
FloatToStrF(Argument,ffFixed,ffixed,9999,Precision)
|
-
G
- General number format. The next argument in the Args array should be a floating point value.
The argument is converted to a decimal string using fixed point notation or scientific notation,
depending on which gives the shortest result. Precision is used to determine the number of
digits after the decimal point.
In short, the G specifier formats it’s arguument as follows:
FloatToStrF(Argument,ffGeneral,Precision,3)
|
-
M
- Currency format. the next argument in the varArgs array must be a floating point value. The
argument is converted to a decimal string using currency notation. This means that
fixed-point notation is used, but that the currency symbol is appended. If precision is
specified, then then it overrides the CurrencyDecimals global variable used in the FloatToStrF
(780)
In short, the M specifier formats it’s arguument as follows:
FloatToStrF(Argument,ffCurrency,9999,Precision)
|
-
N
- Number format. This is the same as fixed point format, except that thousand separators are
inserted in the resulting string.
-
P
- Pointer format. The next argument in the Args array must be a pointer (typed or untyped). The
pointer value is converted to a string of length 8, representing the hexadecimal value of the
pointer.
-
S
- String format. The next argument in the Args array must be a string. The argument is simply
copied to the result string. If Precision is specified, then only Precision characters are
copied to the result string.
-
X
- hexadecimal format. The next argument in the Args array must be an integer. The
argument is converted to a hexadecimal string with just enough characters to contain
the value of the integer. If Precision is specified then the resulting hexadecimal
representation will have at least Precision characters in it (with a maximum value of
32).
-
Errors:
- In case of error, an EConversionError exception is raised. Possible errors are:
- Errors in the format specifiers.
- The next argument is not of the type needed by a specifier.
- The number of arguments is not sufficient for all format specifiers.
-
See also:
- FormatBuf (793)
Listing: sysutex/ex71.pp
Program example71;
{$mode objfpc}
{ This program demonstrates the Format function }
Uses sysutils;
Var P : Pointer;
fmt,S : string;
Procedure TestInteger;
begin
Try
Fmt:='[%d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%%]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%10d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
fmt:='[%.4d]';S:=Format (fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%10.4d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:10d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:10.4d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:-10d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:-10.4d]';S:=Format (fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%-*.*d]';S:=Format (fmt,[4,5,10]);writeln(Fmt:12,' => ',s);
except
On E : Exception do
begin
Writeln ('Exception caught : ',E.Message);
end;
end;
writeln ('Press enter');
readln;
end;
Procedure TestHexaDecimal;
begin
try
Fmt:='[%x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%10x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%10.4x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:10x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:10.4x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:-10x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:-10.4x]';S:=Format (fmt,[10]);writeln(Fmt:12,' => ',s);
Fmt:='[%-*.*x]';S:=Format (fmt,[4,5,10]);writeln(Fmt:12,' => ',s);
except
On E : Exception do
begin
Writeln ('Exception caught : ',E.Message);
end;
end;
writeln ('Press enter');
readln;
end;
Procedure TestPointer;
begin
P:=Pointer(1234567);
try
Fmt:='[0x%p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s);
Fmt:='[0x%10p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s);
Fmt:='[0x%10.4p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s);
Fmt:='[0x%0:p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s);
Fmt:='[0x%0:10p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s);
Fmt:='[0x%0:10.4p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s);
Fmt:='[0x%0:-10p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s);
Fmt:='[0x%0:-10.4p]';S:=Format (fmt,[P]);writeln(Fmt:12,' => ',s);
Fmt:='[%-*.*p]';S:=Format (fmt,[4,5,P]);writeln(Fmt:12,' => ',s);
except
On E : Exception do
begin
Writeln ('Exception caught : ',E.Message);
end;
end;
writeln ('Press enter');
readln;
end;
Procedure TestString;
begin
try
Fmt:='[%s]';S:=Format(fmt,['This is a string']);Writeln(fmt:12,'=> ',s);
fmt:='[%0:s]';s:=Format(fmt,['This is a string']);Writeln(fmt:12,'=> ',s);
fmt:='[%0:18s]';s:=Format(fmt,['This is a string']);Writeln(fmt:12,'=> ',s);
fmt:='[%0:-18s]';s:=Format(fmt,['This is a string']);Writeln(fmt:12,'=> ',s);
fmt:='[%0:18.12s]';s:=Format(fmt,['This is a string']);Writeln(fmt:12,'=> ',s);
fmt:='[%-*.*s]';s:=Format(fmt,[18,12,'This is a string']);Writeln(fmt:12,'=> ',s);
except
On E : Exception do
begin
Writeln ('Exception caught : ',E.Message);
end;
end;
writeln ('Press enter');
readln;
end;
Procedure TestExponential;
begin
Try
Fmt:='[%e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%10e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%10.4e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:10e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:10.4e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:-10e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:-10.4e]';S:=Format (fmt,[1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%-*.*e]';S:=Format (fmt,[4,5,1.234]);writeln(Fmt:12,' => ',s);
except
On E : Exception do
begin
Writeln ('Exception caught : ',E.Message);
end;
end;
writeln ('Press enter');
readln;
end;
Procedure TestNegativeExponential;
begin
Try
Fmt:='[%e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%10e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%10.4e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:10e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:10.4e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:-10e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:-10.4e]';S:=Format (fmt,[-1.234]);writeln(Fmt:12,' => ',s);
Fmt:='[%-*.*e]';S:=Format (fmt,[4,5,-1.234]);writeln(Fmt:12,' => ',s);
except
On E : Exception do
begin
Writeln ('Exception caught : ',E.Message);
end;
end;
writeln ('Press enter');
readln;
end;
Procedure TestSmallExponential;
begin
Try
Fmt:='[%e]';S:=Format (Fmt,[0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%10e]';S:=Format (Fmt,[0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%10.4e]';S:=Format (Fmt,[0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:e]';S:=Format (Fmt,[0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:10e]';S:=Format (Fmt,[0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:10.4e]';S:=Format (Fmt,[0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:-10e]';S:=Format (Fmt,[0.0123]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:-10.4e]';S:=Format (fmt,[0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%-*.*e]';S:=Format (fmt,[4,5,0.01234]);writeln(Fmt:12,' => ',s);
except
On E : Exception do
begin
Writeln ('Exception caught : ',E.Message);
end;
end;
writeln ('Press enter');
readln;
end;
Procedure TestSmallNegExponential;
begin
Try
Fmt:='[%e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%10e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%10.4e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:10e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:10.4e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:-10e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%0:-10.4e]';S:=Format (fmt,[-0.01234]);writeln(Fmt:12,' => ',s);
Fmt:='[%-*.*e]';S:=Format (fmt,[4,5,-0.01234]);writeln(Fmt:12,' => ',s);
except
On E : Exception do
begin
Writeln ('Exception caught : ',E.Message);
end;
end;
writeln ('Press enter');
readln;
end;
begin
TestInteger;
TestHexadecimal;
TestPointer;
TestExponential;
TestNegativeExponential;
TestSmallExponential;
TestSmallNegExponential;
teststring;
end.
-
Declaration:
- Function FormatBuf(Var Buffer; BufLen : Cardinal; Const Fmt; fmtLen :
Cardinal; Const Args : Array of const) : Cardinal;
-
Description:
- Format
-
Errors:
-
-
See also:
Listing: sysutex/ex72.pp
-
Declaration:
- Function FormatFloat(Const format: String; Value: Extended): String;
-
Description:
- FormatFloat formats the floating-point value given by Value using the format specifications
in Format. The format specifier can give format specifications for positive, negative or zero
values (separated by a semicolon).
If the formatspecifier is empty or the value needs more than 18 digits to be correctly
represented, the result is formatted with a call to FloatToStrF (780) with the ffGeneral
format option.
The following format specifiers are supported:
-
0
- is a digit place holder. If there is a corresponding digit in the value being formatted, then
it replaces the 0. If not, the 0 is left as-is.
-
#
- is also a digit place holder. If there is a corresponding digit in the value being formatted,
then it replaces the #. If not, it is removed. by a space.
-
.
- determines the location of the decimal point. Only the first ’.’ character is taken into account.
If the value contains digits after the decimal point, then it is replaced by the value of
the DecimalSeparator character.
-
,
- determines the use of the thousand separator character in the output string. If the format
string contains one or more ’,’ charactes, then thousand separators will be used. The
ThousandSeparator character is used.
-
E+
- determines the use of scientific notation. If ’E+’ or ’E-’ (or their lowercase counterparts)
are present then scientific notation is used. The number of digits in the output string
is determined by the number of 0 characters after the ’E+’
-
;
- This character separates sections for positive, negative, and zero numbers in the format
string.
-
Errors:
- If an error occurs, an exception is raised.
-
See also:
- FloatToStr (779)
Listing: sysutex/ex89.pp
-
Declaration:
- Function IntToHex(Value: integer; Digits: integer): string;
-
Description:
- IntToHex converts Value to a hexadecimal string representation. The result will contain at
least Digits characters. If Digits is less than the needed number of characters, the string
will NOT be truncated. If Digits is larger than the needed number of characters, the result
is padded with zeroes.
-
Errors:
- None.
-
See also:
- IntToStr (796), StrToInt
Listing: sysutex/ex73.pp
-
Declaration:
- Function IntToStr(Value: integer): string;
-
Description:
- IntToStr coverts Value to it’s string representation. The resulting string has only as much
characters as needed to represent the value. If the value is negative a minus sign is prepended
to the string.
-
Errors:
- None.
-
See also:
- IntToHex (796), StrToInt (804)
Listing: sysutex/ex74.pp
-
Declaration:
- Function IsValidIdent(const Ident: string): boolean;
-
Description:
- IsValidIdent returns True if Ident can be used as a compoent name. It returns False
otherwise. Ident must consist of a letter or underscore, followed by a combination of letters,
numbers or underscores to be a valid identifier.
-
Errors:
- None.
-
See also:
Listing: sysutex/ex75.pp
-
Declaration:
- Function LastDelimiter(const Delimiters, S: string): Integer;
-
Description:
- LastDelimiter returns the last occurrence of any character in the set Delimiters in the
string S.
-
Errors:
-
-
See also:
Listing: sysutex/ex88.pp
-
Declaration:
- Function LeftStr(const S: string; Count: integer): string;
-
Description:
- LeftStr returns the Count leftmost characters of S. It is equivalent to a call to
Copy(S,1,Count).
-
Errors:
- None.
-
See also:
- RightStr (801), TrimLeft (807), TrimRight (808), Trim (807)
Listing: sysutex/ex76.pp
-
Declaration:
- Function LoadStr(Ident: integer): string;
-
Description:
- This function is not yet implemented. resources are not yet supported.
-
Errors:
-
-
See also:
-
Declaration:
- Function LowerCase(const s: string): string;
-
Description:
- LowerCase returns the lowercase equivalent of S. Ansi characters are not taken into account,
only ASCII codes below 127 are converted. It is completely equivalent to the lowercase
function of the system unit, and is provided for compatiibility only.
-
Errors:
- None.
-
See also:
- AnsiLowerCase (766), UpperCase (809), AnsiUpperCase (773)
Listing: sysutex/ex77.pp
-
Declaration:
- Function NewStr(const S: string): PString;
-
Description:
- NewStr assigns a new dynamic string on the heap, copies S into it, and returns a pointer to
the newly assigned string.
This function is obsolete, and shouldn’t be used any more. The AnsiString mechanism also
allocates ansistrings on the heap, and should be preferred over this mechanism.
-
Errors:
- If not enough memory is present, an EOutOfMemory exception will be raised.
-
See also:
- AssignStr (775), DisposeStr (779)
For an example, see AssignStr (775).
-
Declaration:
- Function QuotedStr(const S: string): string;
-
Description:
- QuotedStr returns the string S, quoted with single quotes. This means that S is enclosed
in single quotes, and every single quote in S is doubled. It is equivalent to a call to
AnsiQuotedStr(s, '''').
-
Errors:
- None.
-
See also:
- AnsiQuotedStr (767), AnsiExtractQuotedStr (765).
Listing: sysutex/ex78.pp
-
Declaration:
- Function RightStr(const S: string; Count: integer): string;
-
Description:
- RightStr returns the Count rightmost characters of S. It is equivalent to a call to
Copy(S,Length(S)+1-Count,Count).
If Count is larger than the actual length of S only the real length will be used.
-
Errors:
- None.
-
See also:
- LeftStr (798),Trim (807), TrimLeft (807), TrimRight (808)
Listing: sysutex/ex79.pp
-
Declaration:
- Function StrFmt(Buffer,Fmt : PChar; Const args: Array of const) : Pchar;
-
Description:
- StrFmt will format fmt with Args, as the Format (784) function does, and it will store
the result in Buffer. The function returns Buffer. Buffer should point to enough space to
contain the whole result.
-
Errors:
- for a list of errors, see Format (784).
-
See also:
- StrLFmt (802), FmtStr (783), Format (784), FormatBuf (793)
Listing: sysutex/ex80.pp
-
Declaration:
- Function StrLFmt(Buffer : PCHar; Maxlen : Cardinal;Fmt : PChar; Const args:
Array of const) : Pchar;
-
Description:
- StrLFmt will format fmt with Args, as the Format (784) function does, and it will store
maximally Maxlen characters of the result in Buffer. The function returns Buffer. Buffer
should point to enough space to contain MaxLen characters.
-
Errors:
- for a list of errors, see Format (784).
-
See also:
- StrFmt (801), FmtStr (783), Format (784), FormatBuf (793)
Listing: sysutex/ex81.pp
-
Declaration:
- Function StrToFloat(Const S : String) : Extended;
-
Description:
- StrToFloat converts the string S to a floating point value. S should contain a valid stroing
representation of a floating point value (either in decimal or scientific notation). If the string
contains a decimal value, then the decimal separator character can either be a ’.’ or the value
of the DecimalSeparator variable.
-
Errors:
- If the string S doesn’t contain a valid floating point string, then an exception will be raised.
-
See also:
- TextToFloat (805),FloatToStr (779),FormatFloat (794),StrToInt (804)
Listing: sysutex/ex90.pp
-
Declaration:
- Function StrToInt(const s: string): integer;
-
Description:
- StrToInt will convert the string Sto an integer. If the string contains invalid characters or
has an invalid format, then an EConvertError is raised.
To be successfully converted, a string can contain a combination of numerical characters,
possibly preceded by a minus sign (-). Spaces are not allowed.
-
Errors:
- In case of error, an EConvertError is raised.
-
See also:
- IntToStr (796), StrToIntDef (805)
Listing: sysutex/ex82.pp
-
Declaration:
- Function StrToIntDef(const S: string; Default: integer): integer;
-
Description:
- StrToIntDef will convert a string to an integer. If the string contains invalid characters or
has an invalid format, then Default is returned.
To be successfully converted, a string can contain a combination of numerical characters,
possibly preceded by a minus sign (-). Spaces are not allowed.
-
Errors:
- None.
-
See also:
- IntToStr (796), StrToInt (804)
Listing: sysutex/ex83.pp
-
Declaration:
- Function TextToFloat(Buffer: PChar; Var Value: Extended): Boolean;
-
Description:
- TextToFloat converts the string in Buffer to a floating point value. Buffer should
contain a valid stroing representation of a floating point value (either in decimal or scientific
notation). If the buffer contains a decimal value, then the decimal separator character can
either be a ’.’ or the value of the DecimalSeparator variable.
The function returns True if the conversion was successful.
-
Errors:
- If there is an invalid character in the buffer, then the function returns False
-
See also:
- StrToFloat (803),FloatToStr (779), FormatFloat (794)
Listing: sysutex/ex91.pp
-
Declaration:
- Function Trim(const S: string): string;
-
Description:
- Trim strips blank characters (spaces) at the beginning and end of S and returns the resulting
string. Only #32 characters are stripped.
If the string contains only spaces, an empty string is returned.
-
Errors:
- None.
-
See also:
- TrimLeft (807), TrimRight (808)
Listing: sysutex/ex84.pp
-
Declaration:
- Function TrimLeft(const S: string): string;
-
Description:
- TrimLeft strips blank characters (spaces) at the beginning of S and returns the resulting
string. Only #32 characters are stripped.
If the string contains only spaces, an empty string is returned.
-
Errors:
- None.
-
See also:
- Trim (807), TrimRight (808)
Listing: sysutex/ex85.pp
-
Declaration:
- Function TrimRight(const S: string): string;
-
Description:
- Trim strips blank characters (spaces) at the end of S and returns the resulting string. Only
#32 characters are stripped.
If the string contains only spaces, an empty string is returned.
-
Errors:
- None.
-
See also:
- Trim (807), TrimLeft (807)
Listing: sysutex/ex86.pp
-
Declaration:
- Function UpperCase(const s: string): string;
-
Description:
- UpperCase returns the uppercase equivalent of S. Ansi characters are not taken into account,
only ASCII codes below 127 are converted. It is completely equivalent to the UpCase function
of the system unit, and is provided for compatiibility only.
-
Errors:
- None.
-
See also:
- AnsiLowerCase (766), LowerCase (799), AnsiUpperCase (773)
-
Errors:
-
-
See also:
Listing: sysutex/ex87.pp