ScriptreplaceUmlaut

From 40tude Dialog Wiki

This OnBeforeSending-Script changes all occurences of german umlaut characters to their expanded form, e.g. ä > ae, etc.


program OnBeforeSendingMessage;


function StringReplace(S, OldPattern, NewPattern: string): string;
var
  SearchStr, Patt, NewStr: string;
  Offset: Integer;
begin
  SearchStr := S;
  Patt := OldPattern;
  NewStr := S;
  Result := '';
  while SearchStr <> '' do
  begin
    Offset := AnsiPos(Patt, SearchStr);
    if Offset = 0 then
    begin
      Result := Result + NewStr;
      Break;
    end;
    Result := Result + Copy(NewStr, 1, Offset - 1) + NewPattern;
    NewStr := Copy(NewStr, Offset + Length(OldPattern), 2147483647);
    SearchStr := Copy(SearchStr, Offset + Length(Patt), 2147483647);
  end;
end;

function OnBeforeSendingMessage(var Message: TStringlist; Servername: string; IsEmail: boolean):boolean;
var s:string;
begin
result:=true;
s:=message.text;
s:=StringReplace(s,'ü,'ue');
s:=stringreplace(s,'ö,'oe');
s:=stringreplace(s,'ä,'ae');
s:=stringreplace(s,'Ü,'Ue');
s:=stringreplace(s,'Ö,'Oe');
s:=stringreplace(s,'Ä,'Ae');
s:=stringreplace(s,'ß,'ss');
message.text:=s;
end;

begin
end.