Jump to content

replace string in text file


Recommended Posts

Hi, Im trying to replace a bunch of strings from a text file,

here's my code but i cant get it to work correctly, any advice is greatly appreciated

#include <GUIConstants.au3>

$GUI = GUICreate("Form1", 128, 256, 338, 275, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE))
$Label_ID = GUICtrlCreateLabel("Votre N° téléphone SIP :", 4, 13, 120, 17)
$ID = GUICtrlCreateInput("mon id", 4, 30, 121, 21)
$Label_MDP = GUICtrlCreateLabel("Votre mot de passe :", 4, 61, 101, 17)
$MDP = GUICtrlCreateInput("mon mot de passe", 4, 78, 121, 21)
$Label_Proxy = GUICtrlCreateLabel("Proxy SIP:", 4, 109, 53, 17)
$PROXY = GUICtrlCreateInput("mon proxy", 4, 126, 121, 21)
$Label_Domaine = GUICtrlCreateLabel("Domaine SIP:", 4, 157, 69, 17)
$DOMAINE = GUICtrlCreateInput("mon domaine", 4, 174, 121, 21)
$GO = GUICtrlCreateButton("GO", 4, 224, 121, 25)
GUISetState(@SW_SHOW)

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $GO
            go()
    EndSelect
WEnd

Func go()
$save = FileSaveDialog( "Enregistrez le profil!", @DesktopCommonDir, "UpdateProfile (*.conf)", 2, "updateProfile.conf")
If @error Then
    MsgBox(4096,"","Enregistrement annulé!")
EndIf

$file = FileOpen("updateprofile.conf", 0)
If $file = -1 Then
    MsgBox(0, "Erreur", "Le fichier ne peut etre ouvert!")
    Exit
EndIf

FileRead($file)
$a = StringReplace($file,"<ID>",GUICtrlRead($ID))
$b = StringReplace($a,"<MDP>",GUICtrlRead($MDP))
$c = StringReplace($b,"<PROXY>",GUICtrlRead($PROXY))
$fini = StringReplace($c,"<DOMAINE>",GUICtrlRead($DOMAINE))

FileOpen ( $save, 2 )
FileWriteLine($save, $fini)
FileClose($save)
EndFunc
Edited by meekaah
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...