Page 1 sur 1

[Résolu] Retirer un mot d'un fichier

Publié : mar. 25/juin/2019 10:44
par SPH
Salut,

je seche sur un truc : comment retirer un mot d'une liste de mots contenu dans un fichier ?

Code : Tout sélectionner

#dst=1

chemin$="c:\Temp\1.txt"

If ReadFile(#dst, chemin$)
  While Eof(#dst) = 0           ; loop as long the 'end of file' isn't reached
    mot$=ReadString(#dst)
    mot$=LCase(mot$)
    
    If mot$="la"
      ;;;;;;;;;;;;;;;;;;;; retirer le mot "la"
    EndIf
    
  Wend
  CloseFile(#dst)
EndIf
Thx 8) 8O :idea:

Re: Retirer un mot d'un fichier

Publié : mar. 25/juin/2019 11:09
par Christophe
Bonjour SPH

Une methode simple consiste à réécrire ton fichier sans le "la"

Code : Tout sélectionner

#dst=1
#tmp=2

chemin$="c:\Temp\1.txt"
temp$="c:\temp\2.txt"

CreateFile(#tmp, temp$)

If ReadFile(#dst, chemin$)
  While Eof(#dst) = 0           ; loop as long the 'end of file' isn't reached
    mot$=ReadString(#dst)
    mot$=LCase(mot$)
    
    If mot$="la"
      ;;;;;;;;;;;;;;;;;;;; retirer le mot "la"
      Continue
    Else
      WriteStringN(#tmp, mot$)
    EndIf
    
  Wend
  CloseFile(#dst)
  CloseFile(#tmp)
  DeleteFile(chemin$)
  RenameFile(temp$, chemin$)
EndIf

Re: Retirer un mot d'un fichier

Publié : mar. 25/juin/2019 11:19
par SPH
Merci 8)

C'etait fort simple en effet :idea:

Re: Retirer un mot d'un fichier

Publié : mar. 25/juin/2019 11:24
par Mindphazer
Ou en passant par une liste :

Code : Tout sélectionner

#dst=1

chemin$="c:\Temp\1.txt"
NewList mots.s()

If ReadFile(#dst, chemin$)
  While Eof(#dst) = 0           ; loop as long the 'end of file' isn't reached
    mot$=ReadString(#dst)
    mot$=LCase(mot$)
    If mot$="la"
      ;;;;;;;;;;;;;;;;;;;; retirer le mot "la"
    Else
      AddElement(mots())
      mots() = mot$
    EndIf
  Wend
  CloseFile(#dst)
EndIf

If OpenFile(#dst, chemin$)
  ForEach mots()
    WriteStringN(#dst, mots())
  Next
EndIf

Re: Retirer un mot d'un fichier

Publié : mar. 25/juin/2019 12:40
par SPH
Jamais fait mais interessant 8) :idea: