Jump to content

_ReplaceStringInFile


gigilihooie
 Share

Recommended Posts

Ok, I know this is VERY simple (and I know I did it yesterday) but I cant get it now. :) I looked through all the help files and couldnt get it.

I want inputbox which you can input some text, press the go button and it replaces a piece of text in a text file.

#include <GUIConstantsEx.au3>
#Include <File.au3>
Opt("TrayIconHide", 1)
GUICreate("", 131, 100, -1, -1)

$string = GUICtrlCreateInput("", 5, 10, 100, 20)
$go = GUICtrlCreateButton("go", 5, 40, 30, 20)

GUISetState()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg        
        Case $go
            _ReplaceStringInFile("string.txt", "Ok", $string)
            
        Case $GUI_EVENT_CLOSE
            Exit
            
    EndSwitch
WEnd

Dont judge me :)

Edited by gigilihooie
Link to comment
Share on other sites

Ok, I know this is VERY simple (and I know I did it yesterday) but I cant get it now. :) I looked through all the help files and couldnt get it.

I want inputbox which you can input some text, press the go button and it replaces a piece of text in a text file.

#include <GUIConstantsEx.au3>
#Include <File.au3>
Opt("TrayIconHide", 1)
GUICreate("", 131, 100, -1, -1)

$string = GUICtrlCreateInput("", 5, 10, 100, 20)
$go = GUICtrlCreateButton("go", 5, 40, 30, 20)

GUISetState()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg        
        Case $go
            _ReplaceStringInFile("string.txt", "Ok", $string)
            
        Case $GUI_EVENT_CLOSE
            Exit
            
    EndSwitch
WEnd

Dont judge me :)

Here come da judge.

$sStr = FileRead("String.Txt")
$sStr = StringReplace($sStr, "OK", GUICtrlRead($String))
$oFile = FileOpen("String.txt", 2)
FileWrite($oFile, $sStr)
FileClose($oFile)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Here come da judge.

$sStr = FileRead("String.Txt")
 $sStr = StringReplace($sStr, "OK", GUICtrlRead($String))
 $oFile = FileOpen("String.txt", 2)
 FileWrite($oFile, $sStr)
 FileClose($oFile)
@George ***

I went to your site ( looks nice ) clicked on Contact and then later I clicked on About. The about link from the contact page kinks to a plain white page

Thought you might like to know

8)

NEWHeader1.png

Link to comment
Share on other sites

@George ***

I went to your site ( looks nice ) clicked on Contact and then later I clicked on About. The about link from the contact page kinks to a plain white page

Thought you might like to know

8)

Thanks. What browser? I had that problem in FF last week and I thought I fixed it, if not then I'll look again.

Oh, wait a sec. Did you click the About from the Contact page? If so then that page has the same problem as the one I fixed the other day and I'll correct it the same way. It's a typo where I entered \ instead of /. IE is forgiving on that but not FF.

Can you try it from the Main page?

Thanks

NM

I could have sworn that I did a Global Search & replace for that against the site. Would have been swearing for nothing. It's fixed now. Thanks @Val

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

All is good now!!

8)

Thanks @Val. I would have probably never noticed because I seldom go to the site using FF and I most assuredly would not have checked the Contacts page. Of course I do have a link verifyer but I never think to use it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Worked Perfect, thank you mate.

Would it be possable to make it read\wright to the file when it is hidden?

It should be. Post your working code again so we can look at it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#Include <File.au3>
Opt("TrayIconHide", 1)
GUICreate("", 131, 100, -1, -1)

$string = GUICtrlCreateInput("", 5, 10, 100, 20)
$go = GUICtrlCreateButton("go", 5, 40, 30, 20)

GUISetState()

FileSetAttrib("string.txt", "H")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg        
        Case $go
            $sStr = FileRead("String.Txt")
            $sStr = StringReplace($sStr, "OK", GUICtrlRead($String))
            $oFile = FileOpen("String.txt", 2)
            FileWrite($oFile, $sStr)
            FileClose($oFile)
            
        Case $GUI_EVENT_CLOSE
            Exit
            
    EndSwitch
WEnd

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#Include <File.au3>
Opt("TrayIconHide", 1)
GUICreate("", 131, 100, -1, -1)

$string = GUICtrlCreateInput("", 5, 10, 100, 20)
$go = GUICtrlCreateButton("go", 5, 40, 30, 20)

GUISetState()

FileSetAttrib("string.txt", "H")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg        
        Case $go
            $sStr = FileRead("String.Txt")
            $sStr = StringReplace($sStr, "OK", GUICtrlRead($String))
            $oFile = FileOpen("String.txt", 2)
            FileWrite($oFile, $sStr)
            FileClose($oFile)
            
        Case $GUI_EVENT_CLOSE
            Exit
            
    EndSwitch
WEnd
No problem with that. It will work. Also don't forget that you can set/unset File attribs as required shoud that become necessary.

FileSetAttrib("string.txt", "+HR")

FileSetAttrib("string.txt","-R")

FileWrite("string.txt", "Some string")

FileSetAttrib("string.txt","+R")

BTW: So far you have no code in there that requires the file.au3 file that you #included.

FileSetAttrib and FileWrite are built-in functions.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thank you very much, and I know, that is just the 1/100th of the code.

How would I put that in my code? Something like.

Case $go
            $sStr = FileRead("String.Txt")
            $sStr = StringReplace($sStr, "OK", GUICtrlRead($String))
            $oFile = FileOpen("String.txt", 2)
            FileSetAttrib("string.txt", "+HR")
            FileSetAttrib("string.txt","-R")
            FileWrite($oFile, $sStr)
            FileSetAttrib("string.txt","+R")
            FileClose($oFile)
? Edited by gigilihooie
Link to comment
Share on other sites

Thank you very much, and I know, that is just the 1/100th of the code.

How would I put that in my code? Something like.

Case $go
            $sStr = FileRead("String.Txt")
            $sStr = StringReplace($sStr, "OK", GUICtrlRead($String))
            $oFile = FileOpen("String.txt", 2)
            FileSetAttrib("string.txt", "+HR")
            FileSetAttrib("string.txt","-R")
            FileWrite($oFile, $sStr)
            FileSetAttrib("string.txt","+R")
            FileClose($oFile)
?
If you are going to use FileOpen() then you have to set the attribs BEFORE that line and AFTER The FileClose.

Case $go
            $sStr = FileRead("String.Txt")
            $sStr = StringReplace($sStr, "OK", GUICtrlRead($String))
    ;;FileSetAttrib("string.txt", "+HR");; If this is already the right attribs then no need for this
    ;; it was only used as an example
            FileSetAttrib("string.txt","-R")
            $oFile = FileOpen("String.txt", 2)
            FileWrite($oFile, $sStr)
            FileClose($oFile)
            FileSetAttrib("string.txt","+R")
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...