Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   how to use the option flag rfReplaceAll in ReplaceStr (https://www.delphipraxis.net/204753-how-use-option-flag-rfreplaceall-replacestr.html)

piedad 25. Jun 2020 15:39

how to use the option flag rfReplaceAll in ReplaceStr
 
Hallo Guys,
I Need some help. I am trying something very simple: to build a function to calculate the email addresse from the first Name and last Name for a loop in a QDA Batch.
Since i am Living in Germany know, I am using the german Keyboard, so I have to replace my ä with ae, and so on.
Not a big deal. But trying to use the Option rfReplaceAll I am getting stucked.
I tried to define it as a type, as a set, Nothing is working with an Syntax Error. Could you give me a hint? I am sure it is because a Little type Definition and I am new in Delphi.:
Many thanks in Advance and best regards
Piedad

Here is my last code

// calculate the email adresse from the related PErson
function eMailAdresseCalculator(Person: String): string ;
type
TReplaceFlags = [rfReplaceAll, rfIgnoreCase];
var
FirstName : String;
LastName : String
joint : Index;
options : TReplaceFlags;

begin

joint := Pos(' ', Person);
FirstName:= LowerCase(Trim(LeftStr(Person,joint)));
LastName := LowerCase(Trim(RightStr(Person,(Length(Person)-joint))));
options := rfReplaceAll;

Result := FirstName + '.' + LastName +'@Firma.com';
Result := ReplaceStr(Result,'ä','ae',options);
Result := ReplaceStr(Result,'ö','oe',options);
Result := ReplaceStr(Result,'ü','ue',options);

end;

DieDolly 25. Jun 2020 15:40

AW: how to use the option flag rfReplaceAll in ReplaceStr
 
Why do you re-declare TReplaceFlags ?

Delphi-Quellcode:
options := [rfReplaceAll];
ReplaceStr(Result,'ä','ae',options);

Der schöne Günther 25. Jun 2020 15:52

AW: how to use the option flag rfReplaceAll in ReplaceStr
 
By the way: You will probably want to substitute ß with ss as well

himitsu 25. Jun 2020 18:00

AW: how to use the option flag rfReplaceAll in ReplaceStr
 
Declaring this type is not really right
and it's totally wrong how it was declared. (ENUM <> SET)


ReplaceStr does not have this parameter, because everything is always replaced there and the case sensitivity is controlled by the function name.

Delphi-Quellcode:
// System.StrUtils
S := ReplaceStr(S, Old, New); // same as StringReplace(S, Old, New, [rfReplaceAll])
S := ReplaceText(S, Old, New); // same as StringReplace(S, Old, New, [rfReplaceAll, rfIgnoreCase])

// System.SysUtils
S := StringReplace(S, Old, New, [rfReplaceAll]);

// System.SysUtils : TStringHelper
S := S.Replace(Old, New); // implicit rfReplaceAll
S := S.Replace(Old, New, [rfReplaceAll]);


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:27 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz