Skip to content

Str

Convert a numerical or enumeration value to a string.

Declaration

Source position: system.fpd line 66

  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(var 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);
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);

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

Var
  S : String;

begin
  Str(one, s);
  Writeln(S); 
end.          

Errors

None.

See also

Name Description
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.