griffin Posted May 4, 2006 Share Posted May 4, 2006 Hi There I am a newbie to autoit scripting. I have to enter text into a text file on a certain position. I managed to get the script to enter the text into the file. What i am struggling with is getting it to the right place! I need some assistance! Regards Griffin Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 4, 2006 Share Posted May 4, 2006 (edited) Hi There I am a newbie to autoit scripting. I have to enter text into a text file on a certain position. I managed to get the script to enter the text into the file. What i am struggling with is getting it to the right place!I need some assistance!RegardsGriffinHI,what about FileReadToArray() and then check every line with StringInStr() <> 0 Then "found at position is returned". Now you can add the text behind it.Just a quick thought. So long,Mega Edited May 4, 2006 by th.meger Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 4, 2006 Moderators Share Posted May 4, 2006 HI, what about FileReadToArray() and then check every line with StringInStr() <> 0 Then "found at position is returned". Now you can add the text behind it. Just a quick thought. So long, MegaAlso keep in mind that _FileReadToArray() is in Beta, and you could use _FileWriteToLine() once the string that your looking for has been found:Local $nArray = '', $TextToFind = 'Whatever I need to find', $FileLocation = 'Location To File' _FileReadToArray($FileLocation, $nArray) For $x = 1 To UBound($nArray) - 1 If StringInStr($nArray[$x], $TextToFind) Then _FileWriteToLine($FileLocation, $x, 'Add This To Line ', 0); 0 adds it, 1 replaces the line with what text you want to replace with ExitLoop; Use this if you only want it to replace the first instance it finds of it EndIf NextBoth _FileReadToArray() and _FileWriteToArray() require Beta: AutoIt Beta Here Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 4, 2006 Share Posted May 4, 2006 (edited) Also keep in mind that _FileReadToArray() is in Beta, and you could use _FileWriteToLine() once the string that your looking for has been found:Local $nArray = '', $TextToFind = 'Whatever I need to find', $FileLocation = 'Location To File' _FileReadToArray($FileLocation, $nArray) For $x = 1 To UBound($nArray) - 1 If StringInStr($nArray[$x], $TextToFind) Then _FileWriteToLine($FileLocation, $x, 'Add This To Line ', 0); 0 adds it, 1 replaces the line with what text you want to replace with ExitLoop; Use this if you only want it to replace the first instance it finds of it EndIf NextBoth _FileReadToArray() and _FileWriteToArray() require Beta: AutoIt Beta Here HI SmOke_N, everything totally right what you are saying. I just thought of my soultion, because with _FileWriteToLine it could be hard to write text in a given line (like insert). So long, Mega Edited May 4, 2006 by th.meger Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
griffin Posted May 4, 2006 Author Share Posted May 4, 2006 I looked @ FileReadline, but I have no programming experience.. I will have a look @ FileReadToArray.. Thx ALL Link to comment Share on other sites More sharing options...
ChrisL Posted May 4, 2006 Share Posted May 4, 2006 Something like.... $file = FileOpen("myfile.txt", 0) $NewFile = FileOpen ( "myfile.tmp", 2 ) $searchString="my search string" $relacementString="my Replacement String" ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop If $line = $searchString then $Line = $relacementString Endif FileWriteLine ($NewFile, $Line) Wend FileClose ( $File ) FileClose ( $NewFile ) FileDelete ( "myfile.txt" ) FileMove("myfile.tmp", "myFile.txt") [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 4, 2006 Share Posted May 4, 2006 HI, without StringInStr() checking, you ' ll always only be able to replace the hole line in a txt file. But, nevertheless nice example to start for him. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Simucal Posted May 4, 2006 Share Posted May 4, 2006 StringRegExpReplace seems like a viable solution as well. Can you post the sample text file and what you are trying to insert? AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc) Link to comment Share on other sites More sharing options...
Valuater Posted May 4, 2006 Share Posted May 4, 2006 (edited) remeber _FileWriteToLine() great for line replacement 8) Edited May 4, 2006 by Valuater Link to comment Share on other sites More sharing options...
Simucal Posted May 4, 2006 Share Posted May 4, 2006 I say just fileread the entire text file into a variable, stringregexpreplace the desired string into its position globally. Then write the contents of the variable back to the file, viola. AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc) 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