Jump to content

Find String in text File


Go to solution Solved by kylomas,

Recommended Posts

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)
Link to comment
Share on other sites

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

Saludos

Link to comment
Share on other sites

  • Solution

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...