SmartPascal
StringOfChar
Function
Creates a string with one character repeated many times System unit
 function StringOfChar ( RepeatCharacter : Char; RepeatCount : Integer ) : string;
Description
The StringOfChar function creates a new string of length RepeatCount, filled by RepeatCharacter characters.
 
This function avoids the need for a for loop, or tedious typing.
Related commands
Concat Concatenates one or more strings into one string
Copy Create a copy of part of a string or an array
Delete Delete a section of characters from a string
DupeString Creates a string containing copies of a substring
Insert Insert a string into another string
Move Copy bytes of data from a source to a destination
SetString Copies characters from a buffer into a string
StringReplace Replace one or more substrings found within a string
StuffString Replaces a part of one string with another
WrapText Add line feeds into a string to simulate word wrap
 
Example code : Display a heading with underline characters beneath
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  // The System unit does not need to be defined
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  text, line : string;

begin
  // Write a heading with -'s as underline characters
  text := '1.An introduction to life as we know it';
  line := StringOfChar('-', Length(text));

  // Display our underlined heading
  ShowMessage(text);
  ShowMessage(line);
end;
 
end.
Hide full unit code
   1.An introduction to life as we know it
   ---------------------------------------