Unit 'System' Package
[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] [#rtl]

Str

Convert a numerical or enumeration value to a string.

Declaration

Source position: system.fpd line 67

procedure Str(

  var X: TNumericType;

  var S: string

);

Description

Str returns a string which represents the value of X. X can be any numerical or enumerated type. The actual declaration of Str is not according to pascal syntax, and should be

procedure Str(const X: TNumericType[:NumPlaces[:Decimals]];var S: String)

Where the optional NumPlaces and Decimals specifiers control the formatting of the string: NumPlaces gives the total width of the string, and Decimals the number of decimals after the decimal separator char.

Str can also be used to convert an enumerated type value to a string representation of the declared enumeration value. That means that the following will work:

Type
  TMyEnum = (One,Two);

Var
  S : String;
begin
  Str(One,S);
  Writeln(S);
end.

This will write One on the screen, which is consistent with the following - equivalent - program:

Type
  TMyEnum = (One,Two);

Var
  S : String;
  E : TMyEnum;
begin
  E:=One;
  Str(E,S);
  Writeln(S);
end.

For scoped enumerated types, only the value is written, which means the following program will have the same output:

{$SCOPEDENUMS+}
Type
  TMyEnum = (One,Two);

Var
  S : String;

begin
  Str(One,S);
  Writeln(S);
end.

Errors

None.

See also

Val

  

Calculate numerical/enumerated value of a string.

Example

Program Example68;

{ Program to demonstrate the Str function. }
Var S : String;

Function IntToStr (I : Longint) : String;

Var S : String;

begin
 Str (I,S);
 IntToStr:=S;
end;

begin
  S:='*'+IntToStr(-233)+'*';
  Writeln (S);
end.

Documentation generated on: Oct 02 2024