ForsakenGod Posted December 26, 2009 Share Posted December 26, 2009 Hello, I am trying to make an programm that would read from a file (1 string) modify it and than write it to another file . Lets say the file we want to read the 1 st line is in thisformat <tryage>Somethink</tryage> and in the output file we want to make it rewrite it into [boomsakalaka]Tryage[/boomsakalaka] Any ideas if this is posible ? Thank you for your time Link to comment Share on other sites More sharing options...
Info Posted December 26, 2009 Share Posted December 26, 2009 (edited) Something like this? expandcollapse popup#include <WindowsConstants.au3> #include <GuiEdit.au3> Global $sFile1 = "text.txt" Global $sFile2 = "text2.txt" If Not FileExists($sFile1) Then FileWrite($sFile1,"one plus one equals three") If Not FileExists($sFile2) Then FileWrite($sFile2,"") $Form1 = GUICreate("Text Modify", 633, 175, -1, -1) $Input1 = GUICtrlCreateInput("three", 8, 8, 105, 21) $Input2 = GUICtrlCreateInput("two", 118, 8, 105, 21) $Input3 = GUICtrlCreateInput("", 180, 120, 150, 21) $Button1 = GUICtrlCreateButton("Replace", 8, 34, 75, 25, 0) $Button2 = GUICtrlCreateButton("Write1", 180, 145, 75, 25, 0) $Button3 = GUICtrlCreateButton("Write2", 255, 145, 75, 25, 0) $Edit1 = GUICtrlCreateEdit(FileRead($sFile1), 344, 8, 281, 81, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL)) $Edit2 = GUICtrlCreateEdit(FileRead($sFile2), 344, 90, 281, 81, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL)) GUISetState(@SW_SHOW) While 1 $read1 = FileRead($sFile1) $read2 = FileRead($sFile2) If $read1 <> GUICtrlRead($Edit1) Then GUICtrlSetData($Edit1, $read1) If $read2 <> GUICtrlRead($Edit2) Then GUICtrlSetData($Edit2, $read2) Switch GUIGetMsg() Case -3 _Close() Case $Button1 $open = FileOpen($sFile2, 2) If Not FileExists($sFile2) Then FileCopy($sFile1,$sFile2) FileWrite($open,StringReplace($read1, GUICtrlRead($Input1), GUICtrlRead($Input2))) FileClose($open) Case $Button2 $open = FileOpen($sFile1, 2) FileWrite($open, GUICtrlRead($Input3)) FileClose($open) Case $Button3 $open = FileOpen($sFile2, 2) FileWrite($open, GUICtrlRead($Input3)) FileClose($open) EndSwitch WEnd Func _Close() GUIDelete($Form1) FileDelete($sFile1) FileDelete($sFile2) Exit EndFunc ;==>_Close Edited December 26, 2009 by Info Link to comment Share on other sites More sharing options...
ForsakenGod Posted December 26, 2009 Author Share Posted December 26, 2009 Something like this? expandcollapse popup#include <WindowsConstants.au3> #include <GuiEdit.au3> Global $sFile1 = "text.txt" Global $sFile2 = "text2.txt" If Not FileExists($sFile1) Then FileWrite($sFile1,"one plus one equals three") If Not FileExists($sFile2) Then FileWrite($sFile2,"") $Form1 = GUICreate("Text Modify", 633, 175, -1, -1) $Input1 = GUICtrlCreateInput("three", 8, 8, 105, 21) $Input2 = GUICtrlCreateInput("two", 118, 8, 105, 21) $Input3 = GUICtrlCreateInput("", 180, 120, 150, 21) $Button1 = GUICtrlCreateButton("Replace", 8, 34, 75, 25, 0) $Button2 = GUICtrlCreateButton("Write1", 180, 145, 75, 25, 0) $Button3 = GUICtrlCreateButton("Write2", 255, 145, 75, 25, 0) $Edit1 = GUICtrlCreateEdit(FileRead($sFile1), 344, 8, 281, 81, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL)) $Edit2 = GUICtrlCreateEdit(FileRead($sFile2), 344, 90, 281, 81, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL)) GUISetState(@SW_SHOW) While 1 $read1 = FileRead($sFile1) $read2 = FileRead($sFile2) If $read1 <> GUICtrlRead($Edit1) Then GUICtrlSetData($Edit1, $read1) If $read2 <> GUICtrlRead($Edit2) Then GUICtrlSetData($Edit2, $read2) Switch GUIGetMsg() Case -3 _Close() Case $Button1 $open = FileOpen($sFile2, 2) If Not FileExists($sFile2) Then FileCopy($sFile1,$sFile2) FileWrite($open,StringReplace($read1, GUICtrlRead($Input1), GUICtrlRead($Input2))) FileClose($open) Case $Button2 $open = FileOpen($sFile1, 2) FileWrite($open, GUICtrlRead($Input3)) FileClose($open) Case $Button3 $open = FileOpen($sFile2, 2) FileWrite($open, GUICtrlRead($Input3)) FileClose($open) EndSwitch WEnd Func _Close() GUIDelete($Form1) FileDelete($sFile1) FileDelete($sFile2) Exit EndFunc ;==>_Close Well thanks for this but i probably sayd what i didnt want to . Acually i wanted to make smthink that has format <Blablabla>$Needet</Blablabla> Appear <Somethink>$Needet</somethink> so the mid information stays is it possible? Anyway thanks for your script above its an amazing example Link to comment Share on other sites More sharing options...
ForsakenGod Posted December 29, 2009 Author Share Posted December 29, 2009 Bump ? ^^ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 29, 2009 Moderators Share Posted December 29, 2009 ForsakenGod,If all your lines are of the format <Blablabla>UseThisBit</Blablabla> with NO other <> characters, and you want them all to read <Somethink>UseThisBit<Somethink>, than the following should work:#include <Array.au3> ; Simulate loading a file into an array with _FileReadToArray Global $aFile[4] = [3, "<Blablabla>$Needet</Blablabla>", "<Blablabla>$Needet</Blablabla>", "<Blablabla>$Needet</Blablabla>"] ; Show what we have at the start _ArrayDisplay($aFile, "Initial") For $i = 1 To $aFile[0] $sMiddleText = StringRegExpReplace($aFile[$i], "(?i)<.*>(.*)<.*>", "$1") $aNewLine = "<Somethink>" & $sMiddleText & "<Somethink>" $aFile[$i] = $aNewLine Next ; then use FileWriteToArray to rewrite the file ; Show what we have at the end _ArrayDisplay($aFile, "Final")Note that the _ArrayDisplay lines are just to show you the result and the #include <Array.au3> is only there for that function. You will need to add another include to getthe _File* functions to work whe you come to use them.M23P.S> If you want to look really snazzy, than you can replace the 3 lines in the For...Next loop with just the one: $aFile[$i] = "<Somethink>" & StringRegExpReplace($aFile[$i], "(?i)<.*>(.*)<.*>", "$1") & "<Somethink>" Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ForsakenGod Posted January 2, 2010 Author Share Posted January 2, 2010 ForsakenGod, If all your lines are of the format <Blablabla>UseThisBit</Blablabla> with NO other <> characters, and you want them all to read <Somethink>UseThisBit<Somethink>, than the following should work: #include <Array.au3> ; Simulate loading a file into an array with _FileReadToArray Global $aFile[4] = [3, "<Blablabla>$Needet</Blablabla>", "<Blablabla>$Needet</Blablabla>", "<Blablabla>$Needet</Blablabla>"] ; Show what we have at the start _ArrayDisplay($aFile, "Initial") For $i = 1 To $aFile[0] $sMiddleText = StringRegExpReplace($aFile[$i], "(?i)<.*>(.*)<.*>", "$1") $aNewLine = "<Somethink>" & $sMiddleText & "<Somethink>" $aFile[$i] = $aNewLine Next ; then use FileWriteToArray to rewrite the file ; Show what we have at the end _ArrayDisplay($aFile, "Final") Note that the _ArrayDisplay lines are just to show you the result and the #include <Array.au3> is only there for that function. You will need to add another include to getthe _File* functions to work whe you come to use them. M23 P.S> If you want to look really snazzy, than you can replace the 3 lines in the For...Next loop with just the one: $aFile[$i] = "<Somethink>" & StringRegExpReplace($aFile[$i], "(?i)<.*>(.*)<.*>", "$1") & "<Somethink>" Ohh mow i understand ! Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now