program DeleteString;
var
s: string;
StartPos: integer;
begin
s := GetField(fieldTranslatedTitle);
StartPos := pos('rip', AnsiLowerCase(s));
while StartPos > 0 do
begin
s := copy(s, 0, StartPos - 1) + copy(s, StartPos + 3, Length(s));
StartPos := pos('rip', AnsiLowerCase(s));
end;
SetField(fieldTranslatedTitle, s);
end.
Be careful, as the script will delete ALL "rip" from the title and so affect words like "Ripper" or "Strip", too (like your routine does). So it might be better/safer, e.g. if rip is always found on the beginning of the line, to compare the first 4 characters explicitly ('rip' and a space) and then delete these ones only. At least you might want to use 'rip ' (with a space) instead of 'rip'.
Merci bad4u pour ta réponse, effectivement c'est une solution.
Par contre si je veux l'appliquer sur une série de mots (french, dvd, divx, ripped, XviD...) ça va être galère pour faire le script et le faire évoluer (ajout de mots clés).
En fait, il n'existe pas une commande qui empêche juste la distinction entre majuscule/minuscule ?
----------
Thank you Bad4u for your reply, it is actually a solution. But if I want to implement a series of words (french, dvd, divx, ripped, XviD ...) it will be hard to do the script and to change (adding keywords).
There is not something that just prevents the distinction between uppercase / lowercase?
-----------
Tu peux créer une fonction qui effectue le remplacement d'une chaîne donnée en paramètre. Comme dans le fichier "stringutils1.pas" : ce sont des fonctions rajoutées et "génériques".
Il suffit alors ensuite d'appeler plusieurs fois ta fonction en passant chaque fois un mot différent.
program NewScript;
var
s: string;
begin
SetField(fieldTranslatedTitle, AnsiUpperCase(GetField(fieldTranslatedTitle)));
s := GetField(fieldTranslatedTitle);
s := StringReplace(s, 'RIP ', '');
SetField(fieldTranslatedTitle, s);
SetField(fieldTranslatedTitle, AnsiUpFirstLetter(AnsiLowerCase(GetField(fieldTranslatedTitle))));
end.
Well, your solution might have unwanted effects on original text layout for upper/lower case characters on some titles.. if you put the search string into a constant on the script from above you will have the same expense for changing the "rip" string and add the advantage of keeping all other upper/lower case characters the original way.
program ReplaceUpperLowerCaseString;
const
SearchString = 'rip '; // (in lower case letters)
ReplaceString = ''; // (if you want to replace with another string)
var
s: string;
StartPos: integer;
begin
s := GetField(fieldTranslatedTitle);
StartPos := pos(SearchString, AnsiLowerCase(s));
while StartPos > 0 do
begin
s := copy(s, 0, StartPos - 1) + ReplaceString + copy(s, StartPos + Length(SearchString), Length(s));
StartPos := pos(SearchString, AnsiLowerCase(s));
end;
SetField(fieldTranslatedTitle, s);
end.
You could even define SearchString and ReplaceString as variables and add input fields, so there's no need to edit the script anymore for changing variables..