DelphiFAQ Home Search:
General :: Programming :: Delphi :: Strings
Algorithms for string handling problems, implemented in Delphi but useful for any procedural language.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Format an IP number to have leading 0 (zeroes) using Delphi Pascal

Use the function shown below to format an IP number to have leading 0 (zeroes) using Delphi Pascal.

The output will look like this:

LeadingZeroIPNumber ('1.2.3.4') ==> 001.002.003.004
LeadingZeroIPNumber ('1.212.3.124') ==> 001.212.003.124

function LeadingZeroIPNumber (sIP : string) : string;
 var
   i : integer;
   cnt : integer;
 begin
   Result := '';
   cnt := 1;
   for i := length(sIP) downto 1 do
   begin
     if sIP[i] = '.' then
     begin
       Result := copy('000', cnt, 3) + Result;
       cnt := 0;
     end;
     Result := sIP[i] + Result;
     cnt := cnt + 1;
   end;
   Result := copy('000', cnt, 3) + Result;
 end;
 

Generated 16:01:38 on Jan 18, 2017