Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- Tests the ApplyTemplate function.
- }
- unit userscript;
- function ApplyTemplate(const template: string; var map: TStringList): string;
- const
- openTag = '{{';
- closeTag = '}}';
- var
- i: Integer;
- name, value: string;
- begin
- Result := template;
- for i := 0 to Pred(map.Count) do begin
- name := map.Names[i];
- value := map.ValueFromIndex[i];
- Result := StringReplace(Result, openTag + name + closeTag, value, [rfReplaceAll]);
- end;
- end;
- function Initialize: integer;
- var
- sl: TStringList;
- template, userString: string;
- begin
- sl := TStringList.Create;
- sl.Values['user'] := 'Mator';
- sl.Values['date'] := '07/01/2015';
- sl.Values['title'] := 'autoMator';
- template := '<{{user}} : {{title}}> Posted {{date}}';
- userString := ApplyTemplate(template, sl);
- AddMessage(userString); // <Mator : autoMator> Posted 07/01/2015
- sl.Free;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment