Jump to content

Recommended Posts

Posted

Hello,

Is there a way to search for and replace a specific string of text in a text file? I have a file named SQL_1 that in the midst of other text contains the text '1/1/07' and '1/31/07'. I want to replace that text with the input variables $BeginDate and $EndDate as shown in the below code. Is there an easier way of doing this other than opening the file in word pad and doing a find and replace?

#include <GUIConstants.au3>

Main(); starts GUI part

Func Main()
GUICreate("New DT Mort and Other Instruments DB Prep", 400, 140)
$bdate = GUICtrlCreateInput("", 205, 5, 80, 20)
$edate = GUICtrlCreateInput("", 205, 30, 80, 20)
GUICtrlSetState(-1, $GUI_NODROPACCEPTED)
GUICtrlSetLimit(-1, 10)
GUICtrlCreateLabel ( "Enter the beginning date for the report", 10, 5)
GUICtrlCreateLabel ( "Enter the ending date for the report", 10, 30)
$btn = GUICtrlCreateButton("Continue", 200, 100, 60, 20)
$btn2 = GUICtrlCreateButton("Exit", 130, 100, 60, 20)
GUISetState()
$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        Exit
        Case $msg = $btn2
        Exit
        Case $msg = $btn
            $BeginDate = GUICtrlRead($bdate)
            $EndDate = GUICtrlRead($edate)
        ExitLoop
    EndSelect
WEnd

EndFunc
  • Moderators
Posted

_ReplaceStringInFile()?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

_ReplaceStringInFile()?

I don't see that command in the autoit manual. All I see is a "StringReplace" command, and I don't see any options there for plugging in a file name. Can you give me a reference for the _ReplaceStingInFile() command. Yes, I am a newbie :whistle:

Posted

I don't see that command in the autoit manual. All I see is a "StringReplace" command, and I don't see any options there for plugging in a file name. Can you give me a reference for the _ReplaceStingInFile() command. Yes, I am a newbie :whistle:

Use the help file index to search for functions. This one's in File.au3.
Auto3Lib: A library of over 1200 functions for AutoIt
Posted

Use the help file index to search for functions. This one's in File.au3.

Arg, ok found it. The lines I needed to add to the script were:

_ReplaceStringInFile ("C:\sqlstuff\stats1.sql", '1/1/2007', ($BeginDate))

_ReplaceStringInFile ("C:\sqlstuff\stats1.sql", '1/31/2007', ($EndDate))

_ReplaceStringInFile ("C:\sqlstuff\stats2.sql", '1/1/2007', ($BeginDate))

_ReplaceStringInFile ("C:\sqlstuff\stats2.sql", '1/31/2007', ($EndDate))

_ReplaceStringInFile ("C:\sqlstuff\stats3.sql", '1/1/2007', ($BeginDate))

_ReplaceStringInFile ("C:\sqlstuff\stats3.sql", '1/31/2007', ($EndDate))

Thanks.

Posted

Arg, ok found it. The lines I needed to add to the script were:

_ReplaceStringInFile ("C:\sqlstuff\stats1.sql", '1/1/2007', ($BeginDate))

_ReplaceStringInFile ("C:\sqlstuff\stats1.sql", '1/31/2007', ($EndDate))

_ReplaceStringInFile ("C:\sqlstuff\stats2.sql", '1/1/2007', ($BeginDate))

_ReplaceStringInFile ("C:\sqlstuff\stats2.sql", '1/31/2007', ($EndDate))

_ReplaceStringInFile ("C:\sqlstuff\stats3.sql", '1/1/2007', ($BeginDate))

_ReplaceStringInFile ("C:\sqlstuff\stats3.sql", '1/31/2007', ($EndDate))

Thanks.

OK now I need a function that will just find a specific string in the above named text files and report the number of occurances. Looked in help file and don't see it. Is there a function for that?
Posted

; read the file = $File_read

$File_read = "This is a true story about is and is-not in an abis...lol" 

$count = StringReplace($File_read, "is", "nada")

MsgBox(0,0, @extended)

8)

Cool beans, this works. THANKS!!! The function one looks good too, just have to figure out how I would use it.
  • Moderators
Posted

$File_read = "This is a true story about is and is-not in an abis...lol" 
$nNumberFound = _StringReturnOccurence($File_read, 'is')
MsgBox(64, 'Info', $nNumberFound)

Func _StringReturnOccurence($sString, $sFind)
    StringReplace($sString, $sFind, '')
    Return @extended
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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
×
×
  • Create New...