program pics;
var   N : integer;
      OutString : string;
begin
  for N := 1 to 6 do
    begin
      Str(2*N, OutString);
      writeln('image'+ OutString)
    end
end.

That is the code I've got and here is its output:

image2
image4
image6
image8
image10
image12

but here is the output format that I want:

image002
image004
image006
image008
image010
image012

Have you got a neat way of recoding it?

use the function

/code
function PadStrL(st: string; ch: char; Len: byte): string;
{ Liefert einen String links aufgefüllt mit ch's von der Länge Len }
var
temp : string;
begin
temp := st;
while Length(temp) < Len do
temp := ch + temp;
result := temp;
end;
/code

use the function
( once more, but corrrectly formatted )

function PadStrL(st: string; ch: char; Len: byte): string;
  { Liefert einen String links aufgefüllt mit ch's von der Länge Len  }
var
  temp : string;
begin
  temp := st;
  while Length(temp) < Len do
    temp := ch + temp;
  result := temp;
end;

You could also use the StrOfChar function in the SysUtils unit.

function make_filename( i: integer ): string;
  begin
  result := '';
  if (i < 0) or (i > 999) then exit;

  result := intToStr( i );
  result := 'image' +strOfChar( '0', 3 -length( result ) ) +result
  end;

Hope this helps.

Thanks to you guys for the functions.
It was a nice early morning surprise for me, here in Australia, to find your responses.
I'll try them out shortly.
Meanwhile, I managed to cobble a solution last night before hitting the sack:

program pics;
var   N,M : byte;
      OutString : string;
begin
  for N := 1 to 6 do
    begin
      Str(2*N, OutString);
      write('image');
      for M := 1 to 3 - Length(OutString) do
        write('0');
      writeln(OutString)
    end
end.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.