Trimming text from a string

My code right now is giving me a string that looks like: ":slight_smile:

http://www=2Egoogle=2Ecom/
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

Sorry"

and I want to do two things with it. Firstly I want to delete everything before and after the link so that I can just paste it into a web browser. Secondly I want to turn those =2E things into periods so it will look like http://www.google.com. Any help would be much appreciated. Thank you

Might be a whole lot easier to fix the code that generates the string than to fix the string after the fact - why not post that bit?

Yeah, I was going to say that you can probably just get the url through applescirpt. But here’s a simple example of how you might do that from your string:

set t to “http://www=2Egoogle=2Ecom/
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>”
set o to offset of “http:” in t
set t to text o thru -1 of t
if (count paragraphs of t) > 1 then
set t to text 1 thru -2 of (first paragraph of t)
end if
set d to text item delimiters of AppleScript
set text item delimiters of AppleScript to {“=2E”}
try
set temp_list to text items of t
set text item delimiters of AppleScript to {“.”}
set t to temp_list as string
set text item delimiters of AppleScript to d
on error
set text item delimiters of AppleScript to d
beep 2
return
end try
open location t

gl,

Come to think of it, if there’s always a backslash at the end of the url, then you don’t need the conditional statement:

set t to “http://www=2Egoogle=2Ecom/
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>”
set o to offset of “http:” in t
set t to text o thru -1 of t
set t to text 1 thru -2 of (first paragraph of t)
set d to text item delimiters of AppleScript
set text item delimiters of AppleScript to {“=2E”}
try
set temp_list to text items of t
set text item delimiters of AppleScript to {“.”}
set t to temp_list as string
set text item delimiters of AppleScript to d
on error
set text item delimiters of AppleScript to d
beep 2
return
end try
open location t

gl,

If the third line of the string is the URL, this will work:

set foo to (do shell script "/bin/echo" & space & quoted form of theString & space & "| /usr/bin/sed -e 's/=2E/\\./g' -ne '3p'")

If it’s a different line, just change the “3p” part to accomodate. E.g., “2p” will print the second line.

Thanks guys! I finally got the script to work. It was actually pulling php links so I added something to remove everything from the ending for that as well so here’s the final product.

set o to offset of "http:" in (text item i of wordList)
set p to offset of "php3" in (text item i of wordList)
set t to text (o) thru (p + 3) of text item i of wordList
set d to text item delimiters of AppleScript
try
	set text item delimiters of AppleScript to {"=2E"}
	set temp_list to text items of t
	set text item delimiters of AppleScript to {"."}
	set text item delimiters of AppleScript to d
end try

Works perfectly. Thanks to everyone again for all the help!

Henry