program FindReplace;
const
WholeWord = True;
Search = 'BB01';
Replace = 'Bathroom Toiletries';
Field = fieldCategory;
var
s: string;
begin
s := GetField(Field);
if WholeWord then
begin
if s = Search then
SetField(Field, Replace);
end
else
SetField(Field, StringReplace(s, Search, Replace));
end.
If I add extra search / replace variables in the const section it complains of duplicate values... Do I need to create different scripts for every find & replace value I specify?
You do not especially have to define consts for that: you can directly put the values in the code instead of using the constants and then duplicate lines which do the work.
Else if you still want to use consts, each have to have different names, and then you have to duplicate code lines below so you repeat them to apply to the different consts.
(not sure if my explanation is clear? )
With the hope to be useful to you, look at viewtopic.php?t=4017&highlight=
and especially the procedure replaceWord in the code where I make morel changes in some fields.
const
WholeWord = True;
Search = 'BB01';
Replace = 'Foam & Creme Baths';
Field = fieldCategory;
const
WholeWord = True;
Search = 'BB02';
Replace = 'Shower Gels and Body Washes';
Field = fieldCategory;
How do I phrase this properly? How do I define the one consts from the other? I would try writing it in code instead, but I haven't a clue where to start!
program FindReplace;
const
WholeWordCateg = True;
SearchCateg = 'BB01';
ReplaceCateg = 'Bathroom Toiletries';
WholeWordCountry = True;
SearchCountry = 'US';
ReplaceCountry = 'USA';
var
s: string;
begin
s := GetField(fieldCategory);
if WholeWordCateg then
begin
if s = SearchCateg then
SetField(fieldCategory, ReplaceCateg);
end
else
SetField(Field, StringReplace(s, SearchCateg, ReplaceCateg));
s := GetField(fieldCountry);
if WholeWordCountry then
begin
if s = SearchCountry then
SetField(fieldCountry, ReplaceCountry);
end
else
SetField(Field, StringReplace(s, SearchCountry, ReplaceCountry));
end.
or directly make the code, keeping only useful stuff, e.g.:
program FindReplace;
var
s: string;
begin
s := GetField(fieldCategory);
if s = 'BB01' then
SetField(fieldCategory, 'Bathroom Toiletries');
s := GetField(fieldCountry);
if s = 'US' then
SetField(fieldCountry, 'USA');
end.