Sign in to follow this  
Followers 0
angelong9

Help with replacing text problem

9 posts in this topic

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!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Somebody help me please? Thank you! :D

Share this post


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

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

Ah, yes, it works now.. I didn't know how to delete the parts after the slash, now I do! Thank you again! Rep+ :D

Share this post


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


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

Ah, another problem! How come this script doesn't work for .txt file with multilines of links? It only replaces the last link.. Could you tell me how to loop it if thats what im missing? Thanks!

Share this post


Link to post
Share on other sites

Your best bet would be to use FileReadLine() to separate the lines into single URLs. Then you just have to loop that until you get to the last line. Then write the file outside the loop.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

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