Getting everything to the right of a / as a string

Hello All,

I need to get a string from a variable. I need to get everything from the right of the “/”.

example: server/share

So basically i just want the word share.
Any ideas?

Thanks,
Galen

Maybe this will work.

set text_ to "server/share"

set tids to text item delimiters
try
	set text item delimiters to "/"
	set share_name to last text item of text_
	set text item delimiters to tids
on error
	set text item delimiters to tids
end try
share_name

– Rob

Thanks for the reply!!! This will work great. For some reason i cannot figure out what that script is doing. Is there a way to do it using offset?

Sure, it can be done using offset.

set text_ to "server/share"
try
	set offset_ to offset of "/" in text_
	set share_name to text (offset_ + 1) thru end of text_
on error e
	display dialog e
end try

– Rob

Using AppleScript’s text item delimiters is a novel and efficient way of handling string objects, but it is a little non-intuitive.

What basically happens is when you ask for ‘text items’ of a string, AppleScript uses the current ‘text item delimiters’ to break the string into chunks where each occurrence of the delimiter marks a chunk boundary. You get a list as a result.

In the example of “server/share” as the input and ‘/’ as the ‘text item delimiters’, asking for ‘text items of’ the string returns a list {“server”, “share”}

Rob’s code simply returns the last item in the list, in this case “share”.

If the delimiter had been set to the character ‘e’, the result would be {“s”, “rv”, “r/shar”, “”}

If you want to use the ‘offset’ model you can:

set theText to "server/share"
set slashPos to offset of "/" in theText -- returns 7
set share_name to characters (slashPos + 1) through -1 of theText as string

In this case I’m using ‘characters x through y’ of the string to extract a substring. Providing negative numbers specifies the character position from the end of the string rather than from the beginning so the above code returns characters 8 through the last character of the input string.

Sweet thank you all. This will help to reduce the size of my current script big time. Thanks Again!!

It’s ovbious Rob and Camelot are great applescripters. Do you guys have any scripts that will send an email. I receive one of three emails every night and based upon the rule I set up in rules I want to send a special and unique email to a third person based on one of the three satisfied conditions. I would like the script to have a place for receipent, subject and message.TIA for yor help.