Sign in to follow this  
Followers 0
James

Using StringReplace

25 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

It did the replacements, but you made it so that the new text is stored in $text and not in $DocEd1.

Edited by Helge

Share this post


Link to post
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.

Share this post


Link to post
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!"

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

[center]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.[/center]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Why are you setting Guictrlsetdata to $DocEd1? goodness

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I really question what your trying to do because by the looks of it your making up some random string, replacing the string with a different string then setting it to a input box and seeing how many things were replaced. Well its only going to replace one every time if I'm not mistaken

Share this post


Link to post
Share on other sites

You want us to nickpick all your stuff this way ?

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.

Share this post


Link to post
Share on other sites

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.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0