MrNice21 Posted February 15, 2008 Share Posted February 15, 2008 hi all i want help i will code a find text at "test.txt" (234) and edit (replace) this to 43234242 how can i make this ? help me plz thx Link to comment Share on other sites More sharing options...
SpookMeister Posted February 15, 2008 Share Posted February 15, 2008 I would love to help, but I just don't understand your question. If English is not your native language, try posting in German/French/Swahili/watever. There are people from all over who visit here and they may be able to help/translate for you. [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
MrNice21 Posted February 15, 2008 Author Share Posted February 15, 2008 hi alli want helpi will code a find text at "test.txt" (234) and edit (replace) this to 43234242 how can i make this ? help me plzthxIch möchte einfach ein prog coden was eine datei öffnet z.b. test.dll und in dieser datei einen bestimmten text z.b. 234 sucht und ihn in 234243423 ändert mehr net hoffe mir kann einer helfen danke ja english is net so mein ding lol*****************is this better ? how can i make a prog was open a file (abc.dll) and find in this file a address "32323" and change this address to "34543535". plz help thx Link to comment Share on other sites More sharing options...
MrNice21 Posted February 16, 2008 Author Share Posted February 16, 2008 help me plz Link to comment Share on other sites More sharing options...
James Posted February 16, 2008 Share Posted February 16, 2008 (edited) So you want to replace text found in a text file? Here is what I would do: 1. Read the file and store it in an array 2. Use StringReplace to replace the text you want to be replaced with (makes sense) 3. Overwrite the file you first read from This works: #include <File.au3> Dim $aRecords Global $File = "text.txt" If Not _FileReadToArray($File, $aRecords) Then MsgBox(4096, @ScriptName, "There was an error reading file!") Exit EndIf For $x = 1 To $aRecords[0] $Replaced = StringReplace($aRecords[$x], "hallo", "hello") MsgBox(0, @ScriptName, $Replaced) Next $New = FileOpen($File, 2) FileWrite($New, $Replaced) FileClose($New) Create a new file in the same directory as the script called "text.txt" in that file write "hello" (without quotes). Run the script. Check the file! Just modified some code from the Helpfile Edited February 16, 2008 by JamesB Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
James Posted February 16, 2008 Share Posted February 16, 2008 Here is a better script which I made into a function! expandcollapse popup#include <File.au3> ;#include <Array.au3> ReplaceInFile(@ScriptDir & '\text.txt', "hello", "hallo") Func ReplaceInFile($io_file, $io_word, $io_replacement) Dim $Records $Lines = _FileCountLines($io_File) If Not _FileReadToArray($io_file, $Records) Then ConsoleWriteError("There was an error reading > " & $io_file & @CRLF) Exit ElseIf _FileReadToArray($io_file, $Records) == "" Then ConsoleWriteError("File was found to be blank!" & @CRLF) ElseIf Not @error Then ConsoleWrite("> File was all good!" & @CRLF) EndIf $File = FileOpen($io_file, 2) ; DEBUG = ConsoleWrite("+> Found: " & $Lines & " lines!" & @CRLF) ; DEBUG = _ArrayDisplay($Records) For $ax = 1 To $Records[0] ConsoleWrite("+> " & $Records[$ax] & @CRLF) $Replace = StringReplace($Records[$ax], $io_word, $io_replacement) ConsoleWrite("+> " & $Replace & @CRLF) ;For $ay = $Lines To UBound($Lines) - 1 ; FileWrite($File, $Replace) ;Next If _FileCountLines($io_file) < UBound($Lines) - 1 Then FileWrite($File, $Replace & @CRLF) Else FileWrite($File, $Replace) EndIf If Not @error Then ConsoleWrite("> Replaced String!" & @CRLF) Else ConsoleWriteError("Error replacing text!" & @CRLF) EndIf Next FileClose($File) EndFunc Same instructions as before Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
MrNice21 Posted February 17, 2008 Author Share Posted February 17, 2008 very very nice big thx for help nice forum! Link to comment Share on other sites More sharing options...
James Posted February 17, 2008 Share Posted February 17, 2008 Glad I helped! Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
RH Posted June 17, 2015 Share Posted June 17, 2015 (edited) Hello all,I tried adapting James's function to something I'm trying to do--changing a constant text string in an XQuery file. It works great as far as the text string is concerned, but unfortunately, it strips out all line breaks. Being a total newbie, I'm not sure whether this happens at the time of reading the file into the array or at the time of output, even less how to fix it. Can anyone point me in the right direction? Many thanks! Edit: I hacked it, without really understanding what I'm doing: I just took out the condition and it works:;If _FileCountLines($io_file) < UBound($Lines) - 1 Then FileWrite($File, $Replace & @CRLF) ;Else ;FileWrite($File, $Replace) ;EndIf Edited June 17, 2015 by RH Link to comment Share on other sites More sharing options...
jchd Posted June 17, 2015 Share Posted June 17, 2015 This thread is 7 year old. Don't you think it's time to start one from scratch and expose your actual problem in full grace? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 17, 2015 Moderators Share Posted June 17, 2015 RH,I agree with jchd - please start a new thread and explain a little more clearly the problem you are having.M23 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...
Recommended Posts