Sign in to follow this  
Followers 0
Joseph

reading through and editing text

9 posts in this topic




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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

joemac4130

SwiftBurns

I 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)

:P

Share this post


Link to post
Share on other sites

thanks for the lighter code

ok 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 commas

http://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

Share this post


Link to post
Share on other sites

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 sdf

Example:

$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

Share this post


Link to post
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
Sign in to follow this  
Followers 0