How to pad a string on the right in Pascal

2 Answers

0 votes
program PadRightProgram;
 
function PadRightCustom(const S: string; N: Integer; PadChar: Char): string;
begin
  PadRightCustom := S;
   
  while Length(PadRightCustom) < N do
    PadRightCustom := PadRightCustom + PadChar;
end;
 
var
  str, padded: string;
begin
  str := 'Pascal';
   
  padded := PadRightCustom(str, 10, '*');
   
  WriteLn('"' + padded + '"');  
end.
 
 
 
(*
run:
 
"Pascal****"
 
*)

 



answered Jul 3, 2025 by avibootz
edited Jul 3, 2025 by avibootz
0 votes
program PadRightProgram;

uses StrUtils;

var
  str, padded: string;
begin
  str := 'Pascal';
  
  padded := PadRight(str, 10); 
  
  WriteLn('"' + padded + '"');    
end.



(*
run:

"Pascal    "

*)

 



answered Jul 3, 2025 by avibootz
...