Remove piece of text string

hi, im a noob trying to make a script that checks in a tag in itunes and removes a certain piece of text if it’s there. It can be anywhere in the tag.

Like this:

tell application "iTunes"
	set currentTag to comment of current track
	if currentTag contains "XYZ" then
		-- ? how do i do this: Remove "XYZ" from currentTag
		set comment of current track to currentTag
	end if
end tell

I can then automate this to make the process on a playlist or so, but i just need that remove thingy.

Hi illi,

Use text item delimiters.


set t to "here's some xyz text"
set s to "xyz"
set utid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {s}
set temp_list to text items of t
set AppleScript's text item delimiters to utid
set t to temp_list as string

gl,

Actually, you shouldn’t use the stored text item delimiters utid, but the replace string. More like this:


set t to "here's some xyz text"
set s to "xyz"
set r to ""
set utid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {s}
set temp_list to text items of t
set AppleScript's text item delimiters to {r}
set t to temp_list as string
set AppleScript's text item delimiters to utid
return t

gl,

Thanks! I’ll try that!

Edit: Works perfect, thanks again