I have a phrase that I am having trouble delimiting. How can I trim off the end after .com in each case?
http://www.myspace.com.23.true
to
http://www.myspace.com
OR
http://www.myspace.com next2
to
http://www.myspace.com
OR
I have a phrase that I am having trouble delimiting. How can I trim off the end after .com in each case?
http://www.myspace.com.23.true
to
http://www.myspace.com
OR
http://www.myspace.com next2
to
http://www.myspace.com
OR
Something like this should handle any of those:
set test to "http://www.myspace.com.23.true"
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {".com"}
set test to first text item of test & ".com"
set AppleScript's text item delimiters to ASTID
return test
Don’t forget the offset command from Standard Additions’ string commands, which is often overlooked. For many situations, it can be perfectly appropriate - and is usually a bit shorter and easier to use:
set t to "http://www.myspace.com.23.true"
t's text 1 thru ((offset of ".com" in t) + 3)
Sure:
set t to "fgsfgffhttp://www.myspace.com"
t's text (offset of "http:" in t) thru end
And yes, if you want to extract some text from somewhere in the middle of a string, you can achieve that with offset, too.