22.8 String handling functions

AdjustLineBreaks

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


Program Example48;

{ This program demonstrates the AdjustLineBreaks function }

Uses sysutils;

Const
  S = 'This is a string'#13'with embedded'#10'linefeed and'+
       #13'CR characters';

Begin
  Writeln (AdjustLineBreaks(S));
End.

AnsiCompareStr

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


Program Example49;

{ This program demonstrates the AnsiCompareStr function }
{$H+}

Uses sysutils;

Procedure TestIt (S1,S2 : String);

Var R : Longint;

begin
  R:=AnsiCompareStr(S1,S2);
  Write ('"',S1,'" is ');
  If R<0 then
    write ('less than ')
  else If R=0 then
    Write ('equal to ')
  else
    Write ('larger than ');
  Writeln ('"',S2,'"');
end;

Begin
  Testit('One string','One smaller string');
  Testit('One string','one string');
  Testit('One string','One string');
  Testit('One string','One tall string');
End.

AnsiCompareText

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


Program Example49;

{ This program demonstrates the AnsiCompareText function }
{$H+}

Uses sysutils;

Procedure TestIt (S1,S2 : String);

Var R : Longint;

begin
  R:=AnsiCompareText(S1,S2);
  Write ('"',S1,'" is ');
  If R<0 then
    write ('less than ')
  else If R=0 then
    Write ('equal to ')
  else
    Write ('larger than ');
  Writeln ('"',S2,'"');
end;

Begin
  Testit('One string','One smaller string');
  Testit('One string','one string');
  Testit('One string','One string');
  Testit('One string','One tall string');
End.

AnsiExtractQuotedStr

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


Program Example51;

{ This program demonstrates the AnsiQuotedStr function }

Uses sysutils;

Var S : AnsiString;

Begin
  S:='He said "Hello" and walked on';
  S:=AnsiQuotedStr(Pchar(S),'"');
  Writeln (S);
  Writeln(AnsiExtractQuotedStr(Pchar(S),'"'));
End.

AnsiLastChar

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


Program Example52;

{ This program demonstrates the AnsiLastChar function }

Uses sysutils;

Var S : AnsiString;
    L : Longint;

Begin
  S:='This is an ansistring.';
  Writeln ('Last character of S is : ',AnsiLastChar(S));
  L:=Longint(AnsiLastChar(S))-Longint(@S[1])+1;
  Writeln ('Length of S is : ',L);
End.

AnsiLowerCase

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


Program Example53;

{ This program demonstrates the AnsiLowerCase function }

Uses sysutils;

Procedure Testit (S : String);

begin
 Writeln (S,' -> ',AnsiLowerCase(S))
end;

Begin
  Testit('AN UPPERCASE STRING');
  Testit('Some mixed STring');
  Testit('a lowercase string');
End.

AnsiQuotedStr

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)

AnsiStrComp

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


Program Example54;

{ This program demonstrates the AnsiStrComp function }

Uses sysutils;

Procedure TestIt (S1,S2 : Pchar);

Var R : Longint;

begin
  R:=AnsiStrComp(S1,S2);
  Write ('"',S1,'" is ');
  If R<0 then
    write ('less than ')
  else If R=0 then
    Write ('equal to ')
  else
    Write ('larger than ');
  Writeln ('"',S2,'"');
end;

Begin
  Testit('One string','One smaller string');
  Testit('One string','one string');
  Testit('One string','One string');
  Testit('One string','One tall string');
End.

AnsiStrIComp

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


Program Example55;

{ This program demonstrates the AnsiStrIComp function }

Uses sysutils;

Procedure TestIt (S1,S2 : Pchar);

Var R : Longint;

begin
  R:=AnsiStrIComp(S1,S2);
  Write ('"',S1,'" is ');
  If R<0 then
    write ('less than ')
  else If R=0 then
    Write ('equal to ')
  else
    Write ('larger than ');
  Writeln ('"',S2,'"');
end;

Begin
  Testit('One string','One smaller string');
  Testit('One string','one string');
  Testit('One string','One string');
  Testit('One string','One tall string');
End.

AnsiStrLastChar

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


Program Example58;

{ This program demonstrates the AnsiStrLastChar function }

Uses sysutils;

Var P : Pchar;
    L : Longint;

Begin
  P:='This is an PChar string.';
  Writeln ('Last character of P is : ',AnsiStrLastChar(P));
  L:=Longint(AnsiStrLastChar(P))-Longint(P)+1;
  Writeln ('Length of P (',P,') is : ',L);
End.

AnsiStrLComp

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


Program Example56;

{ This program demonstrates the AnsiStrLComp function }

Uses sysutils;

Procedure TestIt (S1,S2 : Pchar; L : longint);

Var R : Longint;

begin
  R:=AnsiStrLComp(S1,S2,L);
  Write ('First ',L,' characters of "',S1,'" are ');
  If R<0 then
    write ('less than ')
  else If R=0 then
    Write ('equal to ')
  else
    Write ('larger than ');
  Writeln ('those of "',S2,'"');
end;

Begin
  Testit('One string','One smaller string',255);
  Testit('One string','One String',4);
  Testit('One string','1 string',0);
  Testit('One string','One string.',9);
End.

AnsiStrLIComp

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


Program Example57;

{ This program demonstrates the AnsiStrLIComp function }

Uses sysutils;

Procedure TestIt (S1,S2 : Pchar; L : longint);

Var R : Longint;

begin
  R:=AnsiStrLIComp(S1,S2,L);
  Write ('First ',L,' characters of "',S1,'" are ');
  If R<0 then
    write ('less than ')
  else If R=0 then
    Write ('equal to ')
  else
    Write ('larger than ');
  Writeln ('those of "',S2,'"');
end;

Begin
  Testit('One string','One smaller string',255);
  Testit('ONE STRING','one String',4);
  Testit('One string','1 STRING',0);
  Testit('One STRING','one string.',9);
End.

AnsiStrLower

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


Program Example59;

{ This program demonstrates the AnsiStrLower function }

Uses sysutils;

Procedure Testit (S : Pchar);

begin
 Writeln (S,' -> ',AnsiStrLower(S))
end;

Begin
  Testit('AN UPPERCASE STRING');
  Testit('Some mixed STring');
  Testit('a lowercase string');
End.

AnsiStrUpper

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


Program Example60;

{ This program demonstrates the AnsiStrUpper function }

Uses sysutils;

Procedure Testit (S : Pchar);

begin
 Writeln (S,' -> ',AnsiStrUpper(S))
end;

Begin
  Testit('AN UPPERCASE STRING');
  Testit('Some mixed STring');
  Testit('a lowercase string');
End.

AnsiUpperCase

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


Program Example60;

{ This program demonstrates the AnsiUpperCase function }

Uses sysutils;

Procedure Testit (S : String);

begin
 Writeln (S,' -> ',AnsiUpperCase(S))
end;

Begin
  Testit('AN UPPERCASE STRING');
  Testit('Some mixed STring');
  Testit('a lowercase string');
End.

AppendStr

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


Program Example62;

{ This program demonstrates the AppendStr function }

Uses sysutils;

Var S : AnsiString;

Begin
  S:='This is an ';
  AppendStr(S,'AnsiString');
  Writeln ('S = "',S,'"');
End.

AssignStr

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


Program Example63;

{ This program demonstrates the AssignStr function }
{$H+}

Uses sysutils;

Var P : PString;

Begin
 P:=NewStr('A first AnsiString');
 Writeln ('Before: P = "',P^,'"');
 AssignStr(P,'A Second ansistring');
 Writeln ('After : P = "',P^,'"');
 DisposeStr(P);
End.

BCDToInt

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


Program Example64;

{ This program demonstrates the BCDToInt function }

Uses sysutils;

Procedure Testit ( L : longint);
begin
  Writeln (L,' -> ',BCDToInt(L));
end;

Begin
  Testit(10);
  Testit(100);
  Testit(1000);
End.

CompareMem

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:

CompareStr

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


Program Example65;

{ This program demonstrates the CompareStr function }
{$H+}

Uses sysutils;

Procedure TestIt (S1,S2 : String);

Var R : Longint;

begin
  R:=CompareStr(S1,S2);
  Write ('"',S1,'" is ');
  If R<0 then
    write ('less than ')
  else If R=0 then
    Write ('equal to ')
  else
    Write ('larger than ');
  Writeln ('"',S2,'"');
end;

Begin
  Testit('One string','One smaller string');
  Testit('One string','one string');
  Testit('One string','One string');
  Testit('One string','One tall string');
End.

CompareText

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


Program Example66;

{ This program demonstrates the CompareText function }
{$H+}

Uses sysutils;

Procedure TestIt (S1,S2 : String);

Var R : Longint;

begin
  R:=CompareText(S1,S2);
  Write ('"',S1,'" is ');
  If R<0 then
    write ('less than ')
  else If R=0 then
    Write ('equal to ')
  else
    Write ('larger than ');
  Writeln ('"',S2,'"');
end;

Begin
  Testit('One string','One smaller string');
  Testit('One string','one string');
  Testit('One string','One string');
  Testit('One string','One tall string');
End.

DisposeStr

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).

FloatToStr

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


Program Example67;

{ This program demonstrates the FloatToStr function }

Uses sysutils;

Procedure Testit (Value : Extended);

begin
  Writeln (Value,' -> ',FloatToStr(Value));
  Writeln (-Value,' -> ',FloatToStr(-Value));
end;

Begin
  Testit (0.0);
  Testit (1.1);
  Testit (1.1e-3);
  Testit (1.1e-20);
  Testit (1.1e-200);
  Testit (1.1e+3);
  Testit (1.1e+20);
  Testit (1.1e+200);
End.

FloatToStrF

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


Program Example68;

{ This program demonstrates the FloatToStrF function }

Uses sysutils;

Const Fmt : Array [TFloatFormat] of string[10] =
         ('general','exponent','fixed','number','Currency');

Procedure Testit (Value :  Extended);

Var I,J : longint;
    FF : TFloatFormat;

begin
  For I:=5 to 15 do
    For J:=1 to 4 do
      For FF:=ffgeneral to ffcurrency do
        begin
        Write (Value,'(Prec: ',I:2,', Dig: ',J,', fmt : ',Fmt[ff],') : ');
        Writeln (FloatToStrf(Value,FF,I,J));
        Write (-Value,'(Prec: ',I:2,', Dig: ',J,', fmt : ',Fmt[ff],') : ');
        Writeln (FloatToStrf(-Value,FF,I,J));
        end;
end;

Begin
  Testit (1.1);
  Testit (1.1E1);
  Testit (1.1E-1);
  Testit (1.1E5);
  Testit (1.1E-5);
  Testit (1.1E10);
  Testit (1.1E-10);
  Testit (1.1E15);
  Testit (1.1E-15);
  Testit (1.1E100);
  Testit (1.1E-100);
End.

FloatToText

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


Program Example68;

{ This program demonstrates the FloatToStrF function }

Uses sysutils;

Const Fmt : Array [TFloatFormat] of string[10] =
         ('general','exponent','fixed','number','Currency');

Procedure Testit (Value :  Extended);

Var I,J : longint;
    FF : TFloatFormat;
    S : ShortString;

begin
  For I:=5 to 15 do
    For J:=1 to 4 do
      For FF:=ffgeneral to ffcurrency do
        begin
        Write (Value,'(Prec: ',I:2,', Dig: ',J,', fmt : ',Fmt[ff],') : ');
        SetLength(S,FloatToText (@S[1],Value,FF,I,J));
        Writeln (S);
        Write (-Value,'(Prec: ',I:2,', Dig: ',J,', fmt : ',Fmt[ff],') : ');
        SetLength(S,FloatToText (@S[1],-Value,FF,I,J));
        Writeln (S);
        end;
end;

Begin
  Testit (1.1);
  Testit (1.1E1);
  Testit (1.1E-1);
  Testit (1.1E5);
  Testit (1.1E-5);
  Testit (1.1E10);
  Testit (1.1E-10);
  Testit (1.1E15);
  Testit (1.1E-15);
  Testit (1.1E100);
  Testit (1.1E-100);
End.

FmtStr

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


Program Example70;

{ This program demonstrates the FmtStr function }

Uses sysutils;

Var S : AnsiString;

Begin
  S:='';
  FmtStr (S,'For some nice examples of fomatting see %s.',['Format']);
  Writeln (S);
End.

Format

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:
  1. Errors in the format specifiers.
  2. The next argument is not of the type needed by a specifier.
  3. 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.

FormatBuf

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


Program Example72;

{ This program demonstrates the FormatBuf function }

Uses sysutils;

Var
  S : ShortString;

Const
  Fmt : ShortString =  'For some nice examples of fomatting see %s.';

Begin
  S:='';
  SetLength(S,FormatBuf (S[1],255,Fmt[1],Length(Fmt),['Format']));
  Writeln (S);
End.

FormatFloat

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


Program Example89;

{ This program demonstrates the FormatFloat function }

Uses sysutils;

Const
  NrFormat=9;
  FormatStrings : Array[1..NrFormat] of string = (
        '',
        '0',
        '0.00',
        '#.##',
        '#,##0.00',
        '#,##0.00;(#,##0.00)',
        '#,##0.00;;Zero',
        '0.000E+00',
        '#.###E-0');
  NrValue = 5;
  FormatValues : Array[1..NrValue] of Double =
    (1234,-1234,0.5,0,-0.5);

  Width  = 12;
  FWidth = 20;

Var
  I,J : Integer;
  S : String;

begin
  Write('Format':FWidth);
  For I:=1 to NrValue do
    Write(FormatValues[i]:Width:2);
  Writeln;
  For I:=1 to NrFormat do
    begin
    Write(FormatStrings[i]:FWidth);
    For J:=1 to NrValue do
      begin
      S:=FormatFloat(FormatStrings[I],FormatValues[j]);
      Write(S:Width);
      end;
    Writeln;
    end;
End.

IntToHex

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


Program Example73;

{ This program demonstrates the IntToHex function }

Uses sysutils;

Var I : longint;

Begin
  For I:=0 to 31 do
      begin
      Writeln (IntToHex(1 shl I,8));
      Writeln (IntToHex(15 shl I,8))
      end;
End.

IntToStr

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


Program Example74;

{ This program demonstrates the IntToStr function }

Uses sysutils;

Var I : longint;

Begin
  For I:=0 to 31 do
      begin
      Writeln (IntToStr(1 shl I));
      Writeln (IntToStr(15 shl I));
      end;
End.

IsValidIdent

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


Program Example75;

{ This program demonstrates the IsValidIdent function }

Uses sysutils;

Procedure Testit (S : String);

begin
  Write ('"',S,'" is ');
  If not IsVAlidIdent(S) then
    Write('NOT ');
  Writeln ('a valid identifier');
end;

Begin
  Testit ('_MyObj');
  Testit ('My__Obj1');
  Testit ('My_1_Obj');
  Testit ('1MyObject');
  Testit ('My@Object');
  Testit ('M123');
End.

LastDelimiter

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


Program example88;

{ This program demonstrates the LastDelimiter function }

uses SysUtils;

begin
  Writeln(LastDelimiter('\.:','c:\filename.ext'));
end.

LeftStr

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


Program Example76;

{ This program demonstrates the LeftStr function }

Uses sysutils;

Begin
  Writeln (LeftStr('abcdefghijklmnopqrstuvwxyz',20));
  Writeln (LeftStr('abcdefghijklmnopqrstuvwxyz',15));
  Writeln (LeftStr('abcdefghijklmnopqrstuvwxyz',1));
  Writeln (LeftStr('abcdefghijklmnopqrstuvwxyz',200));
End.

LoadStr

Declaration:
Function LoadStr(Ident: integer): string;
Description:
This function is not yet implemented. resources are not yet supported.
Errors:
See also:

LowerCase

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


Program Example77;

{ This program demonstrates the LowerCase function }

Uses sysutils;

Begin
  Writeln (LowerCase('THIS WILL COME out all LoWeRcAsE !'));
End.

NewStr

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).

QuotedStr

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


Program Example78;

{ This program demonstrates the QuotedStr function }

Uses sysutils;

Var S : AnsiString;

Begin
  S:='He said ''Hello'' and walked on';
  Writeln (S);
  Writeln ('  becomes');
  Writeln (QuotedStr(S));
End.

RightStr

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


Program Example79;

{ This program demonstrates the RightStr function }

Uses sysutils;

Begin
  Writeln (RightStr('abcdefghijklmnopqrstuvwxyz',20));
  Writeln (RightStr('abcdefghijklmnopqrstuvwxyz',15));
  Writeln (RightStr('abcdefghijklmnopqrstuvwxyz',1));
  Writeln (RightStr('abcdefghijklmnopqrstuvwxyz',200));
End.

StrFmt

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


Program Example80;

{ This program demonstrates the StrFmt function }

Uses sysutils;

Var S : AnsiString;

Begin
  SetLEngth(S,80);
  Writeln (StrFmt (@S[1],'For some nice examples of fomatting see %s.',['Format']));
End.

StrLFmt

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


Program Example80;

{ This program demonstrates the StrFmt function }

Uses sysutils;

Var S : AnsiString;

Begin
  SetLEngth(S,80);
  Writeln (StrLFmt (@S[1],80,'For some nice examples of fomatting see %s.',['Format']));
End.

StrToFloat

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


Program Example90;

{ This program demonstrates the StrToFloat function }
{$mode objfpc}
{$h+ }

Uses SysUtils;

Const
  NrValues = 5;
  TestStr : Array[1..NrValues] of string =
           ('1,1','-0,2','1,2E-4','0','1E4');

Procedure Testit;

Var
  I : Integer;
  E : Extended;

begin
  Writeln('Using DecimalSeparator : ',DecimalSeparator);
  For I:=1 to NrValues do
    begin
    Writeln('Converting : ',TestStr[i]);
    Try
      E:=StrToFloat(TestStr[i]);
      Writeln('Converted value : ',E);
    except
      On E : Exception do
        Writeln('Exception when converting : ',E.Message);
    end;
    end;
end;

Begin
  DecimalSeparator:=',';
  Testit;
  DecimalSeparator:='.';
  Testit;
End.

StrToInt

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


Program Example82;

{$mode objfpc}

{ This program demonstrates the StrToInt function }

Uses sysutils;

Begin
  Writeln (StrToInt('1234'));
  Writeln (StrToInt('-1234'));
  Writeln (StrToInt('0'));
  Try
    Writeln (StrToInt('12345678901234567890'));
  except
    On E : EConvertError do
      Writeln ('Invalid number encountered');
  end;
End.

StrToIntDef

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


Program Example82;

{$mode objfpc}

{ This program demonstrates the StrToInt function }

Uses sysutils;

Begin
  Writeln (StrToIntDef('1234',0));
  Writeln (StrToIntDef('-1234',0));
  Writeln (StrToIntDef('0',0));
  Try
    Writeln (StrToIntDef('12345678901234567890',0));
  except
    On E : EConvertError do
      Writeln ('Invalid number encountered');
  end;
End.

TextToFloat

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


Program Example91;

{ This program demonstrates the TextToFloat function }
{$mode objfpc}
{$h+ }

Uses SysUtils;

Const
  NrValues = 5;
  TestStr : Array[1..NrValues] of pchar =
           ('1,1','-0,2','1,2E-4','0','1E4');

Procedure Testit;

Var
  I : Integer;
  E : Extended;

begin
  Writeln('Using DecimalSeparator : ',DecimalSeparator);
  For I:=1 to NrValues do
    begin
    Writeln('Converting : ',TestStr[i]);
    If TextToFloat(TestStr[i],E) then
      Writeln('Converted value : ',E)
    else
      Writeln('Unable to convert value.');
    end;
end;

Begin
  DecimalSeparator:=',';
  Testit;
  DecimalSeparator:='.';
  Testit;
End.

Trim

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


Program Example84;

{ This program demonstrates the Trim function }

Uses sysutils;
{$H+}

Procedure Testit (S : String);

begin
  Writeln ('"',Trim(S),'"');
end;

Begin
  Testit ('  ha ha what gets lost ? ');
  Testit (#10#13'haha ');
  Testit ('              ');
End.

TrimLeft

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


Program Example85;

{ This program demonstrates the TrimLeft function }

Uses sysutils;
{$H+}

Procedure Testit (S : String);

begin
  Writeln ('"',TrimLeft(S),'"');
end;

Begin
  Testit ('  ha ha what gets lost ? ');
  Testit (#10#13'haha ');
  Testit ('              ');
End.

TrimRight

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


Program Example86;

{ This program demonstrates the TrimRight function }

Uses sysutils;
{$H+}

Procedure Testit (S : String);

begin
  Writeln ('"',TrimRight(S),'"');
end;

Begin
  Testit ('  ha ha what gets lost ? ');
  Testit (#10#13'haha ');
  Testit ('              ');
End.

UpperCase

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


Program Example87;

{ This program demonstrates the UpperCase function }

Uses sysutils;

Begin
  Writeln (UpperCase('this will come OUT ALL uPpErCaSe !'));
End.