View Full Version : Need Help with 'String Replace' Function
mystica
06-25-2008, 08:37 PM
Hi. Need some help with 'String Replace' Function. Can anyone help me with this, please:
I'm trying to code a "String Replace" function using an Input-Object and Text-File. I've managed to successfully pass a string from one Text-File to another Text-File, but I want to pass the string from an Input-Object to a TextFile instead. But I can't get it to work.
If anyone thinks they can help out with this, I've attached two Project-Files to demonstrate what I'm trying to do.
NB.
The first Project-File shows where I successfully passed a string from one Text-File to another Text-File (The Text-Files get dropped into the project's CD_Root Folder).
The second Project-File doesn't work, but shows what I'm trying to do (ie. pass a string from the Input-Object to a Text-File that will be generated in the CD_Root Folder). Perhaps, if anyone can figure out a solution, they could could correctly code this second Project-File as an example, and re-attach it with their response.
Thanks.
mwreyf1
06-25-2008, 09:06 PM
What is the purpose of the Input object?
There is no reference to it at all in your code.
mwreyf1
06-25-2008, 09:59 PM
Try this.
It should get you started.
mystica
06-26-2008, 12:44 AM
What is the purpose of the Input object?
There is no reference to it at all in your code.
mwreyf1,
The purpose of the InputObject is to replace the 1st TextFile used in the initial project-file. There is no reference to it in my code because that is what I'm having trouble coding and is what I'm seeking help with.
Basically, I want the user to be able to type data into the InputObject so that when the button is clicked, a string-change is made to the data before it gets written to a TextFile in the CD_Root folder.
In this particular case, when a user inputs a URL beginning with 'www', after clicking the button, the string-change is supposed to rewrite it to the TextFile as: 'http://www'. (ie. www.example1.com is supposed to be converted to http://www.example1.com).
As I mentioned earlier, I've managed to achieve this in the 1st ProjectFile attached (passing the string-change from one TextFile to another) but NOT with the 2nd ProjectFile (passing the string-change from an InputObject to a TextFile).
I'll have a look at the .Apz file you uploaded in your last response, when I get home and see how I go ... but thought it best to elaborate here and now on what I'm trying to do.
Thanks dude.
mwreyf1
06-26-2008, 12:14 PM
Now I see.
This will probably be closer to what your looking for.
No need to create the Links.txt before running.
mrdude
06-27-2008, 02:01 PM
why not try doing something like this m8:
I modded your code so you could get an idea of what to do.
mystica
06-28-2008, 01:17 AM
Now I see.
This will probably be closer to what your looking for.
No need to create the Links.txt before running.
Thanks mwreyf1,
I had a look at your first response last night, and although it's not quite what I'm looking for, I think your code will provide me with enough insight to be able to figure things out.
I see you've attached a second example (many thanks) which I'll also look at later when I get home. Thankyou for your support.
mystica
06-28-2008, 01:21 AM
why not try doing something like this m8:
I modded your code so you could get an idea of what to do.
Thankyou mrdude,
I've not had a look at your example yet as I have to wait until I get home but as both you and mwreyf1 have been so responsive to my question, I'm sure I'll be able to solve the problem using your code as exemplars.
I'll get back to you both when I've had a chance to test things out.
Cheers.
RizlaUK
06-28-2008, 07:57 AM
if all you want to do is add the "HTTP://" to the string in the input object then there is no need to use String.Replace
eg:
strURL = Input.GetText("Input1")
-- make sure the http pars isent already added, if it isent then add it.
if String.Find(strURL, "HTTP://", 1, false) == -1 then
strURL = "HTTP://"..strURL
end
-- Test
Dialog.Message("strURL", strURL);
mystica
06-30-2008, 05:04 PM
if all you want to do is add the "HTTP://" to the string in the input object then there is no need to use String.Replace
eg:
strURL = Input.GetText("Input1")
-- make sure the http pars isent already added, if it isent then add it.
if String.Find(strURL, "HTTP://", 1, false) == -1 then
strURL = "HTTP://"..strURL
end
-- Test
Dialog.Message("strURL", strURL);
RizlaUK,
"http" was just an example. For actual useage, I'm requiring replacement of all kinds of characters. Thanks for your response though ... it's encouraging to receive input from the famous RizlaUK!
mystica
06-30-2008, 05:14 PM
mwreyf1 & mrdude,
Just getting back to you both regarding the help you provided me with and to give you both a huge Thankyou!
mwreyf1, the second example you posted was PERFECT! (exactly what I was looking for) ... so many thanks.
mrdude, many thanks to you also for taking mwreyf1's example one step further and producing something I would never even have thought of!
You've both saved me from weeks of banging my head against the wall, trying to figure it out on my own. So thanks to you guys, my problem is now solved! Only wish my level of coding experience was such that I could return the favour!
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.