Bonjour
Depuis un certain temps, j'ai le couvercle de ma marmite qui fume
Bref, un petit problème qui à priori devrait être simple, puisque les tests en ShowMessages sont impeccables ; mais la réalité de la compile en est une autre.
Je vous donne une version du principe afin de trouver ce qui foire :
Voici également le texte de test allant avec :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 procedure TForm1.Button1Click(Sender: TObject); var StringList, StringLine: TStringList; mot, AmotB: String; i, j: Integer; begin StringList := TStringList.Create; // En vertical = texte StringLine := TStringList.Create; // En horizontal = ligne TRY Memo1.Lines.LoadFromFile('Texte.txt'); StringList.LoadFromFile ('Texte.txt'); for i := 0 to StringList.Count - 1 do begin //------- Seconde StringList analysant mot à mot sur LA sLigne affectée StringLine.Text := StringList[i]; StringLine.Delimiter := ' '; // Delimiteur = SPACE StringLine.QuoteChar := ' '; StringLine.DelimitedText := StringLine.Text; //ShowMessage(StringList[i]); //------- for j := 0 to StringLine.Count - 1 do if pos(AnsiLowerCase('toto'), StringLine[j]) > 0 then begin mot := StringLine[j]; //ShowMessage(mot); // Détection impec pourtant ! AmotB := 'A'+mot+'B'; //ShowMessage(AmotB); // Ici aussi impec ! end; StringList[i] := StringReplace(StringList[i], mot, AmotB, [rfReplaceAll, rfIgnoreCase]); //StringList[i] := StringReplace(StringList[i], mot, AmotB, [rfIgnoreCase]); //StringList[i] := AnsiReplaceText(StringList[i], mot, AmotB); //StringList[i] := AnsiReplaceStr(StringList[i], mot, AmotB); end; ShowMessage(StringList.Text); //Memo1.Text := StringList.Text; FINALLY StringLine.Free; StringList.Free; end; end;
Le but recherché est exclusivement de détecter certains mots et de placer de part et d'autre une string, exemple basé sur le mot de recherche toto :Essai numéro un : toto et totoriri totoririloulou ensuite ...
Second essai : totoririloulou plus totoriri toto voilà !
AtotoririloulouB AtotoloulouB
Toutes les étapes sont franchies avec succès, enfin... à en croire les ShowMessages.
Car en réalité, les remplacements sont très erratiques. En effet ; les ajouts de strings s'effectuent même à l'intérieur des mots
J'ai pourtant testé avec (presque) toutes les fonctions équivalentes à StringReplace() et consorts.
Un grand merci d'avance de votre aide.
Partager