PDA

View Full Version : Replace string help please



mrdude
09-18-2005, 10:07 AM
Hi guys, can anyone tell me how to do this?

Ok I have a document with a certain string value inside it, I then want to make APMS open that document, find the string and then replace it with one from an input box and then save/replace the document with the value from the input box.

How do I go about this - I'm using the demo of APMS 6 but can't find any examples.

Thanks.

Corey
09-18-2005, 10:51 AM
Hi. What format is your "document"?

mrdude
09-18-2005, 11:05 AM
Hi. What format is your "document"?


It's a html web page that has some text in it that I want to be able to change using a database, basically I select an entry in the database and it is then shown in an input box - from the input box I want the enrty to be writen to the html page so that the next time the page is loaded the new text value from the database is shown.

I already have the database working fine and putting the entries in the input box - I am stuck on the searching for a string value part in the html document and then replacing it with the new value from the database.

Dermot
09-18-2005, 12:32 PM
Try this


-- Load in your html file
SourceFile = TextFile.ReadToString("Path and file name of your html file.html")

-- Find and replace the text
OutPutFile = String.Replace("SourceFile", "Text To Replace", "Text to replace with", false)

-- Save the file
TextFile.WriteFromString(OutPutFile, "Path and file name to save as.html", false)

mrdude
09-18-2005, 01:46 PM
Thanks - Got it working with this:




-- Load in your html file
SourceFile = TextFile.ReadToString("AutoPlay\\Docs\\page1.htm")

-- get the data from our input fields
text1 = Input.GetText("Inputmac");

-- Find and replace the text
result = String.Replace(SourceFile, "000123456789", text1, false);

-- Save the file
TextFile.WriteFromString("AutoPlay\\Docs\\page2.htm", result, false)

-- Reload web page ---
Web.LoadURL("Web1", "AutoPlay\\Docs\\page2.htm");