Sign in to follow this  
Followers 0
behdadsoft

Find String in text File

4 posts in this topic

Hi.

I wrote a script that can read a text file and write new text. now I want search in text content and find custom string then add "// " at first find string.Please Guide Me.

Thanks

#RequireAdmin
#include <File.au3>

; Local Var
Local $CreateList = @ScriptDir & "\List.txt"
Local $ReadPath = @DesktopDir & "\Sample.txt"
Local $Array = 0

   Local $ReadList = _FileReadToArray ($ReadPath,$Array,0)
   _FileWriteFromArray ($CreateList,$Array,1)

Share this post


Link to post
Share on other sites



Could go through the array and compare if is true that you want use $array[index]=$array[index] & ""

Saludos


 

venezuela.png Would you like to say thank to Danyfirex using a warmy way?  offer me a cup of coffee... coffee.png

autoit_scripter_blue_userbar.png

       AutoIt...

 

 

Share this post


Link to post
Share on other sites

behdadsoft,

Based on your definition the following should work without having to iterate an array...

#RequireAdmin
#include <File.au3>

; Local Var
Local $CreateList = @ScriptDir & "\List.txt"
Local $ReadPath = @DesktopDir & "\Sample.txt"
local $The_String_To_Seacrh_For = 'some string'

local $str = fileread($ReadPath)
$str = stringreplace($str,$The_String_To_Seacrh_For,'//' & $The_String_To_Seacrh_For,1) ; replace first occurrence only
filewrite($CreateList)

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Thanks kylomas  :)

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