Joseph Posted October 5, 2008 Share Posted October 5, 2008 i'm trying to make something that will read through characters in a txt file and replace or enter what is needed, what would be the best way to do this? http://runecrue.awardspace.comhttp://demopros.awardspace.com Link to comment Share on other sites More sharing options...
TehWhale Posted October 5, 2008 Share Posted October 5, 2008 Maybe.. For $i=1 to _FileCountLines($File) $Read = _FileReadLine($File, $i) $Write = StringReplace($Read, "5", "6") _FileWriteLine($File, $Write, $i) Next ^^^^^^^^^^^^^ NON-WORKING EXAMPLE, just to show you the basics, of how to do that. Link to comment Share on other sites More sharing options...
Joseph Posted October 5, 2008 Author Share Posted October 5, 2008 could u make one working example of replacing text asdf in a notepad txt with 1234, i'm not sure how important the variables and stuff are in that http://runecrue.awardspace.comhttp://demopros.awardspace.com Link to comment Share on other sites More sharing options...
TehWhale Posted October 5, 2008 Share Posted October 5, 2008 Create a .txt file called: script.txt in the same location as this script, and in script.txt put: asdf line one blah asdf kdhjajhasdf 454a 4a5s4f5t7 asdfasdf 445d44asdf45a44 Then run the code below #include <File.au3> $File = @ScriptDir & "\script.txt" For $i=1 To _FileCountLines($File) $Hwnd = FileOpen($File, 0) $Read = FileReadLine($Hwnd, $i) FileClose($Hwnd) $Write = StringReplace($Read, "asdf", "1234") _FileWriteToLine($File, $i, $Write, 1) Next Link to comment Share on other sites More sharing options...
Joseph Posted October 5, 2008 Author Share Posted October 5, 2008 ok that helps a lot from the code that u gave me, it replaces the text that needs to be replaced but then how could i replace asdf with 1234 if there is a string that has only at least asd or at least sdf http://runecrue.awardspace.comhttp://demopros.awardspace.com Link to comment Share on other sites More sharing options...
rasim Posted October 5, 2008 Share Posted October 5, 2008 joemac4130SwiftBurnsI think this will easier and faster:$sFile = "c:\test.txt" $sRead = FileRead($sFile) $sRead = StringReplace($sRead, "asdf", "1234") $hFile = FileOpen($sFile, 2) FileWrite($hFile, $sRead) FileClose($hFile) Link to comment Share on other sites More sharing options...
Joseph Posted October 5, 2008 Author Share Posted October 5, 2008 thanks for the lighter codeok say i have lots of text and there are urls in the textfile below from a gethandle function but some needs to be taken out, the !@#$ characters and only keep the text that has http and .com at the end and seperate by commashttp://www.website1234.com http://www.internetsite99.net !@#$ http://www.notadotcom.net www.dotnetfx.com !@#$ http://youngmetroent.awardspace.com !@#$ variousunwantedtext ..,,...agghh http://demopros.awardspace.com !@#$..aghh!so it would read the text file and rewrite it as only http://www.website1234.com , http://youngmetroent.awardspace.com , http://demopros.awardspace.com http://runecrue.awardspace.comhttp://demopros.awardspace.com Link to comment Share on other sites More sharing options...
rasim Posted October 5, 2008 Share Posted October 5, 2008 joemac4130 from the code that u gave me, it replaces the text that needs to be replaced but then how could i replace asdf with 1234 if there is a string that has only at least asd or at least sdfExample: $sRead = "Helloasdf asdfworld new astest" MsgBox(0, "", StringRegExpReplace($sRead, "(?i)\w*(asd|sdf)\w*", "1234"))oÝ÷ Ú«¨µê$±¬¢«Þl¡û^ÆÖ§vØ^æ«zêå²)íë^Æ×âæÞ®ëajweyû§rب»²ç²ÚzÖ¤zz.¶Ø^ß}7éÈZ§-z»Ú')zaz×±¶ØZ¶¬Ûijw¢f¶Ö§vÇ©z¶y¼¢i³ú®¢×¯+aÆ®¶sbb33c·4fÆRÒgV÷C¶3¢b3#·FW7BçGBgV÷C°¢b33c·5&VBÒfÆU&VBb33c·4fÆR ¢b33c¶&W7VÇBÒ7G&æu&VtWb33c·5&VBÂgV÷C²õRGGåµâb3#·5Ò²b3#²æ6ö×ÆGGåµâb3#·5Ò²b3#²ææWBgV÷C²Â2¤bW'&÷"FVâW@ ¢b33c·5&VBÒgV÷C²gV÷C° ¤f÷"b33c¶ÒFòT&÷VæBb33c¶&W7VÇBÒ b33c·5&VBf׳Òb33c¶&W7VÇE²b33c¶ÒfײgV÷C²ÂgV÷C°¤æW@ ¢b33c¶fÆRÒfÆT÷Vâb33c·4fÆRÂ"¤fÆUw&FRb33c¶fÆRÂb33c·5&VB¤fÆT6Æ÷6Rb33c¶fÆR Link to comment Share on other sites More sharing options...
Joseph Posted October 5, 2008 Author Share Posted October 5, 2008 man that is some leet stuff i finally got it thanks http://runecrue.awardspace.comhttp://demopros.awardspace.com 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