IncludeLeadingChar function
String / Filename routines
Return to Introduction  Previous page  Next page
Unit
acUtils  

Declaration
function IncludeLeadingChar(St: String; Ch: Char): String;  

Description
The IncludeLeadingChar function puts specified character at the beginning of a string if it's not already there. For example result of IncludeTrailingChar('Software\Microsoft\CurrentVersion', '\') will be "\Software\Microsoft\CurrentVersion". It's a typical function that gets rewritten by every programmer.  

Original code
function IncludeLeadingChar(const St: String; Ch: Char): String;  
begin  
  if (St = ''or (St[1] <> Ch) then  
    Result := Ch + St  
  else  
    Result := St;  
end;