Jump to content

Using StringReplace


James
 Share

Recommended Posts

What is the proper way of using StringReplace?

Case $Replace
            $2Find =  InputBox("Replace", "What string/line would you like to replace?")
            $ReplaceWith = InputBox("Replace", "What would you like to replace " & $2Find & " with?")
            
            $text = StringReplace(GuiCtrlRead($DocEd1), $2Find, $ReplaceWith, 0, 0)
            $numreplacements = @extended
            MsgBox(0, "Replace", $numreplacements & " were made!")

It thinks it is making the replacements, and it knows its there. But it doesn't "update" $DocEd1

Secure

Edited by Secure_ICT
Link to comment
Share on other sites

Well I have:

Case $Replace
            $2Find =  InputBox("Replace", "What string/line would you like to replace?")
            $ReplaceWith = InputBox("Replace", "What would you like to replace " & $2Find & " with?")
            
            $DocEd1 = StringReplace(GuiCtrlRead($DocEd1), $2Find, $ReplaceWith, 0, 0)
            $numreplacements = @extended
            MsgBox(0, "Replace", $numreplacements & " were made!")

But that doesn't work either. It says it has replaced it, but nothing changes.

Link to comment
Share on other sites

What is the proper way of using StringReplace?

Case $Replace
            $2Find =  InputBox("Replace", "What string/line would you like to replace?")
            $ReplaceWith = InputBox("Replace", "What would you like to replace " & $2Find & " with?")
            
            $text = StringReplace(GuiCtrlRead($DocEd1), $2Find, $ReplaceWith, 0, 0)
            $numreplacements = @extended
            MsgBox(0, "Replace", $numreplacements & " were made!")

It thinks it is making the replacements, and it knows its there. But it doesn't "update" $DocEd1

Secure

GUICtrlSetData($DocEd1, $Text) ?

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

  • Developers

No, because that would replace the whole of $DocEd1.

ahh you want magic ....

What else do you think you need to do ?

You read the whole text in which you replace a string with another string... logic says you need to store the whole text back into the Edit box ...

:P

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

No, because that would replace the whole of $DocEd1.

Yes it would, and at the same time change the text you would want to change. You don't expect it to just change the text specific and nothing else do you? The thing I see most in your questions, and in rebuttals, is you seem to forget you are not just messing with "one" function. You have to make "everything" work.

Example:

$Main = GUICreate('Example', 250, 350)
$Edit = GUICtrlCreateEdit('This is the text I am going to change.', 10, 10, 230, 290)
$Button = GUICtrlCreateButton('Change', 100, 310, 50, 30)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $Button
            $sReadEdit = GUICtrlRead($Edit)
            GUICtrlSetData($Edit, '')
            GUICtrlSetData($Edit, StringReplace($sReadEdit, 'am going to', 'did'))
    EndSwitch
WEnd

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.

Link to comment
Share on other sites

  • Developers

I don't get you.. What do you mean store?

lets return the question: How do you perceive this replace routine should work ?

Now think in a flowchart step by step process and chart that out for yourself...

Thats how you start a program ... not writing code and "see where the ship will land" ...

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

$DocEd1 = StringReplace(GuiCtrlRead($DocEd1), $2Find, $ReplaceWith, 0, 0)

Now the new text is stored in $DocEd1, but now that you've replaced the control's ID with the text how are you

planning on working with the control again ?

No, because that would replace the whole of $DocEd1.

Well, how are you planning on using the new text then ? Use GUICtrlSetData to update the control with the updated

text, using the controlID you don't have anymore.

Link to comment
Share on other sites

Thanks everyone!

I have done it.

Case $Replace
            $2Find =  InputBox("Replace", "What string/line would you like to replace?")
            $ReplaceWith = InputBox("Replace", "What would you like to replace " & $2Find & " with?")
            $sReadEdit = GUICtrlRead($DocEd1)
            GUICtrlSetData($DocEd1, '')
            $DocEd1 = GUICtrlSetData($DocEd1, StringReplace($sReadEdit, $2Find, $ReplaceWith))
            $numreplacements = @extended
            MsgBox(0, "Replace", $numreplacements & " were made!")

Thankyou SO much.

Edit: It works for the first edit. But then, when you try another edit, it doesn't work.

Edit: Well I don't know what I did, but it will replace more than one now. But it doesn't count the amount of replacments.

Edited by Secure_ICT
Link to comment
Share on other sites

Case $Replace
            $2Find =  InputBox("Replace", "What string/line would you like to replace?")
            $ReplaceWith = InputBox("Replace", "What would you like to replace " & $2Find & " with?")
            $sReadEdit = GUICtrlRead($DocEd1)
            
            GUICtrlSetData($DocEd1, '')
            GUICtrlSetData($DocEd1, StringReplace($sReadEdit, $2Find, $ReplaceWith))
            $numreplacements = @extended
            
            MsgBox(0, "Replace", $numreplacements & " were made!")

It replaces, but doesnt add the amount of replacments.

Link to comment
Share on other sites

  • Developers

Edit: Well I don't know what I did, but it will replace more than one now. But it doesn't count the amount of replacments.

That is because @extended has the value of the last performed function which is GuiCtrlSetData()

$2Find =  InputBox("Replace", "What string/line would you like to replace?")
            $ReplaceWith = InputBox("Replace", "What would you like to replace " & $2Find & " with?")
            $sReadEdit = GUICtrlRead($DocEd1)
            $sReadEdit  = StringReplace($sReadEdit, $2Find, $ReplaceWith)
            $numreplacements = @extended
            GUICtrlSetData($DocEd1, $sReadEdit )
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Why are you setting Guictrlsetdata to $DocEd1? goodness

You want us to nickpick all your stuff this way ?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Ummm no its just he's destroying his control ID when he's been told already that it would, sure if you want to nickpick my stuff since I hardly ever post questions feel free.

sure ... and he will keep on making mistakes like this till he truly understands more about programming ...

Nothing wrong with that ... only Secure really needs to start think about the process more and stop posting every bump he hits.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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