Jump to content
Sign in to follow this  
Senach

Help request with string searching

Recommended Posts

Senach

Greetings all.

Ok, basically where Im stuck this time is searching for quote marks. Ive got a batch of scripts that log into a server, run reports, then email the results to various people. Instead of going through all the scripts every xx days to change the passwords Im playing with creating an #include statement for the new password. I got that going with no problem. Now Im trying to come up with a script that will go through all 186 reports and replace the old password with the new variable from the include.

Basically I want this:

WinWaitActive ("Enter Login and Password")
Send ("username{Enter}")
Send ("password{Enter}")

To turn into this:

WinWaitActive ("Enter Login and Password")
Send ("username{Enter}")
Send (& $newpass & "{Enter}")

I got a script to replace the word pswrd with the $newpswrd but when I try to change it to include the whole line, I run into errors because of the multiple quotes in the line.

Here's the working one:

While 1
    $file = FileFindNextFile($search) 
    $filea = "C:\scripts\test_rpts\" & $file
    If @error Then ExitLoop
    $szSearchString = "password"
    $szReplaceString = "$newpass"
    _ReplaceStringInFile ( $filea, $szSearchString, $szReplaceString)

WEnd

Here's what doesn't:

While 1
    $file = FileFindNextFile($search) 
    $filea = "C:\scripts\test_rpts\" & $file
    If @error Then ExitLoop
    $szSearchString = "Send ("password{Enter}")"
    $szReplaceString = "Send (& $newpass & "{Enter}")"
    _ReplaceStringInFile ( $filea, $szSearchString, $szReplaceString)

WEnd

What can I do to fix this? Is there a way to do a search for a string with quotes?

Thanks all.


"The three rules of the Librarians of Time and Space are: 1) Silence; 2) Books must be returned no later than the date last shown; and 3) Do not interfere with the nature of causality." Terry Pratchett - The Light Fantastic

Share this post


Link to post
Share on other sites
andybiochem

Ok, not sure I get it but how about:

While 1
    $file = FileFindNextFile($search)
    $filea = "C:\scripts\test_rpts\" & $file
    If @error Then ExitLoop
    $szSearchString = 'Send ("password{Enter}")'
    $szReplaceString = 'Send ("' & $newpass & '{Enter}")'
    _ReplaceStringInFile ( $filea, $szSearchString, $szReplaceString)

WEnd

all I changed was this line:

$szReplaceString = 'Send ("' & $newpass & '{Enter}")'

if you want quote marks in a string, define the string with apostrophies:

$ExampleString = 'And then he said "Hello friend" again'

Edited by andybiochem

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

Share this post


Link to post
Share on other sites
Senach

Yep that's what I was missing! :P Thanks andybiochem, I didn't know about using apostrophies.

I knew it was something simple that I just couldn't figure out.

Thanks again!


"The three rules of the Librarians of Time and Space are: 1) Silence; 2) Books must be returned no later than the date last shown; and 3) Do not interfere with the nature of causality." Terry Pratchett - The Light Fantastic

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.