Lire & remplacer mots ds un fichier txt ds VB
Coocool
-
Coocool -
Coocool -
Bonjour,
Je dois faire un petit programme pour un enseignement.
Je voudrais savoir comment faire pour :
1) Lire un fichier texte
2) Remplacer une chaine de caractères (ici, un chemin d'une image) par un autre chemin que l'utilisateur tape dans un textbox...
3) Enregistrer ce fichier modifié là où l'utilisateur veut l'enregistrer
NB : il y a 4 chemins a modifier
Quelqu'un pourrait m'aider ? Merci !!
PS: Je suis débutant.
Je dois faire un petit programme pour un enseignement.
Je voudrais savoir comment faire pour :
1) Lire un fichier texte
2) Remplacer une chaine de caractères (ici, un chemin d'une image) par un autre chemin que l'utilisateur tape dans un textbox...
3) Enregistrer ce fichier modifié là où l'utilisateur veut l'enregistrer
NB : il y a 4 chemins a modifier
Quelqu'un pourrait m'aider ? Merci !!
PS: Je suis débutant.
A voir également:
- Lire & remplacer mots ds un fichier txt ds VB
- Lire le coran en français pdf - Télécharger - Histoire & Religion
- Lire un fichier epub - Guide
- Fichier bin - Guide
- Comment réduire la taille d'un fichier - Guide
- Fichier rar - Guide
2 réponses
Bonjour Coocool,
alors voici deux fonctions :
pour faire l'appel des fonctions et remplacer :
Normalement ca devrait marcher.
Bon courage
Si tu as des problèmes hésite pas ;-)
alors voici deux fonctions :
Public Function FileInMemory(ByVal stFilePath As String) As String 'Variable locale Dim hFile As Integer 'Gestion des erreurs On Error GoTo InBinary 'Initialisation hFile = FreeFile 'Ouverture du fichier Open stFilePath For Input As hFile FileInMemory = Input(LOF(hFile), hFile) 'Ne prend pas les caractères binaires Close hFile Exit Function 'Si problème avec des caractères binaires... InBinary: Close hFile hFile = FreeFile 'Ouverture du fichier Open stFilePath For Binary As hFile FileInMemory = Input(LOF(hFile), hFile) 'Accepte les caractères binaires Close hFile End Function Public Function MemoryInFile(ByVal stFilePath As String, ByVal stData As String) As Boolean 'Variable locale Dim hFile As Integer 'Initialisation hFile = FreeFile MemoryInFile = False 'Gestion des erreurs On Error GoTo fin 'Ouverture du fichier Open stFilePath For Output As hFile Print #hFile, stData Close hFile 'true si Ok MemoryInFile = True fin: End Function
pour faire l'appel des fonctions et remplacer :
Dim str As String Dim a As Boolean str = FileInMemory("C:\...\tonfichier.txt") str = Replace(str, "chemin a remplacer", "text1.text") a = MemoryInFile("C:\...\tonfichier.txt", str)
Normalement ca devrait marcher.
Bon courage
Si tu as des problèmes hésite pas ;-)