Jump to content

Help with replacing text problem


angelong9
 Share

Recommended Posts

Hi guys, I'm a complete newb to AutoIt but there is a tedious thing I want to do with netload.in that only AutoIt could make it easier for me.

For netload.in links, usually the links are like:

1)

http://www.netload.in/dateistySAD12345/hello.rar.htm

But if you go to the link, it'll actually go to

2)

http://www.netload.in/dateistySAD12345.htm

Links are not real btw :D

So what I want the script to do is open a text file with netload links in it(location given by me of course), replace the 1st slash from the right and whatever's behind it with ".htm", THEN replace another string of "http://www." with "http://LOGIN:PASSWORD@", and finally saves and overwrite the same file.

I know this is a lot to ask but I really need this! I don't even know where to start. Please help me with this and I'm sure I can learn something from this :D

Thank you very much!

Link to comment
Share on other sites

Welcome to the forum!

You are looking for string functions. There are many to choose from. Look in the help file for all the functions that deal with strings.

$String = "http://www.netload.in/dateistySAD12345/hello.rar.htm"
$String = StringLeft($String, StringInStr($String, "/", 0, -1) - 1)
$String = StringReplace($String, "http://www.", "http://LOGIN:PASSWORD@")

Just so you can learn a little bit more about Autot, try looking up how to write this string to a file. Look up FileWrite(), FileRead(), FileReadLine(), FileOpen(), and FileClose() in the help file. If you need help, come back with what you tried and we will be glad to help.

Edited by dantay9
Link to comment
Share on other sites

Thank you! Well, I tried it out and read some posts and tried writing something on my own.. It ALMOST worked.. Just one little problem... Please help me :D

Here is my code:

$TextFileName = "Netload.txt"

$String = "http://www."
$String2 = "http://LOGIN:PASSWORD@"

$FileContents = FileRead($TextFileName)
$n = StringInStr($FileContents,"/", 0, -1)
$mid = StringLeft($FileContents, $n-1)
$Replace = $mid & ".htm"
$FileContents = StringReplace($FileContents,$mid,$Replace)
$FileContents = StringReplace($FileContents, $String, $String2)
FileDelete($TextFileName)
FileWrite($TextFileName,$FileContents)

Well $String2 replaces $String just fine, but for the replacing the forward slash and characters after it part, instead of

http://www.netload.in/dateistySAD12345/hello.rar.htm
to http://LOGIN:PASSWORD@netload.in/dateistySAD12345.htm

It became like this:

http://www.netload.in/dateistySAD12345/hello.rar.htm
to http://LOGIN:PASSWORD@netload.in/dateistySAD12345.htm/hello.rar.htm

Please help me fix my code.. Thank you very much!

Edited by angelong9
Link to comment
Share on other sites

Sorry about the wait. I had a soccer game to go to. I think this is what you are trying to do. What you were doing is replacing the text. That was all fine. The only thing you didn't do was delete the string to the right of the slash mark. Here is the easiest way to do it.

$TextFileName = "Netload.txt"

$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents, "http://www.", "http://LOGIN:PASSWORD@")

$n = StringInStr($FileContents, "/", 0, -1)
$FileContents = StringLeft($FileContents, $n - 1)
$FileContents &= ".htm" ;same as $String = $String & ".htm"

FileDelete($TextFileName)
FileWrite("t" & $TextFileName, $FileContents)
Link to comment
Share on other sites

Your welcome. Just for learning purposes, I didn't actually delete the string on the end. All I did was just take the left side of the string. To delete a number of characters from the beginning or the end of a string, use StringTrimLeft() or StringTrimRight(). If you are trying to replace text in the middle, you can use StringReplace($String, "string to find", ""). That will effectively delete the text in the middle.

Link to comment
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
 Share

  • Recently Browsing   0 members

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