Sign in to follow this  
Followers 0
DeeCee

Help needed with StringReplace

4 posts in this topic

Howdy all!

I'm new around here and new to using AutoIt in general, so please be gentle. DeeCee--> :o

After loading a text file into an edit control (no probs), is there a way to copy the contents of the edit control into memory for further processing? I'm hoping to do some heavy processing to the content in memory using StringReplace, then write that data back to a new file, without disturbing the original text. Then I'll start the process over again..

This seems so simple in theory, but after a couple of hours of reading the docs and trying different approaches, I guess I must resort to begging for help. B)

I probably don't need any specific code, but something like: "Hey dummy, first you do this, then this, then..)

Thx for any assistance you can offer,

DeeCee

Share this post


Link to post
Share on other sites



If you can do it WITHOUT AutoIt with the keyboard and mouse

YOU should do it with AutoIT

Post the first try you did because it is difficult to help you from a general stand point.

At least post what you do without AutoIT and we will help you to write the AutoIt counterpart. B)

Share this post


Link to post
Share on other sites

YOU should do it with AutoIT

Okay, that's encouraging.

Since this is part of a much larger program, I'll separate the part that I need help with and post again.

Thx,

DeeCee

Share this post


Link to post
Share on other sites

Got it finally! B)

It may not be pretty, but it works so I thought I'd post it in case someone else run's into a jam.

Here's the code:

#include <GuiConstants.au3>
If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000
GuiCreate("ReplaceString Sample", 750, 480,(@DesktopWidth-750)/2, (@DesktopHeight-600)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$Button_1 = GuiCtrlCreateButton("Open Template File", 10, 10, 145, 25)
$Edit_2 = GuiCtrlCreateEdit("", 10, 40, 730, 160)
$Label_3 = GuiCtrlCreateLabel("This Is the sample output:", 10, 270, 550, 20)
$Edit_4 = GuiCtrlCreateEdit("", 10, 290, 730, 180)
$Button_5 = GuiCtrlCreateButton("Process Edit Control", 570, 210, 140, 40)

GuiSetState()
While 1
  $msg = GuiGetMsg()
  Select
  Case $msg = $GUI_EVENT_CLOSE
          ExitLoop
  Case $msg = $Button_1
        GetTemplateFile()

  Case $msg = $Button_5
        ProcessRecords()
  EndSelect
WEnd
Exit

Func GetTemplateFile()
    $message = "Choose a file..."
    $myTemplate = FileOpenDialog($message, "C:\", "All Files (*.*)", 1 + 4 )
    $TemplateTxt = FileRead($myTemplate, FileGetSize($myTemplate))
    GUICtrlSetData ( $Edit_2, $TemplateTxt)
EndFunc


Func ProcessRecords()
    $NewText = GUICtrlRead($Edit_2)
    $NewText = StringReplace ($NewText,"[FIRSTSTRING]", "my new string!")
    $NewText = StringReplace ($NewText,"[SECONDSTRING]", "my 2nd new string!")
        GUICtrlSetData ( $Edit_4, $NewText)
EndFunc

Here's a sample file for testing purposes:

This is [FIRSTSTRING]
This is [SECONDSTRING]

Thx,

DeeCee

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  
Followers 0