• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Replace slash by underscroe in file name
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Replace slash by underscroe in file name


  • Subject: Re: Replace slash by underscroe in file name
  • From: kai <email@hidden>
  • Date: Thu, 23 Mar 2006 14:48:04 +0000


On 23 Mar 2006, at 14:06, Christian Vinaa wrote:

At 13:18 +0000 23/03/2006, kai wrote:
-------------

to switchText of t from s to r
	set d to text item delimiters
	set text item delimiters to s
	set t to t's text items
	set text item delimiters to r
	set t to t as Unicode text
	set text item delimiters to d
	t
end switchText

set fileName to "name/of/some/file.txt"
set fileName to my (switchText of fileName from "/" to "_")

--> "name_of_some_file.txt"

-------------

would you please explain what in fact is going on behind the scene in the switchtext rutine ?

Sure thing, Christian. Here's a commented version of the switchText handler, with (hopefully) more meaningful variable labels:


-------------

to switchText of currentText from searchString to replaceString

	set storedDelimiters to text item delimiters
	-- this simply stores the current value of
	-- AppleScript's text item delimiters
	-- so they can be restored later
	-- (thus helping to avoid potential problems elsewhere)

	set text item delimiters to searchString
	-- AppleScript's text item delimiters are now set to "/"

	set currentText to currentText's text items
	-- create a list of text items from the original text,
	-- separated at the points where the
	-- current text item delimiter ("/") appeared

	--> {"name", "of", "some", "file.txt"}

	set text item delimiters to replaceString
	-- AppleScript's text item delimiters are now set to "_"

	set currentText to currentText as Unicode text
	-- coerce the list  {"name", "of", "some", "file.txt"} to Unicode text
	-- this operation will also insert the current value
	-- of AppleScript's text item delimiters
	-- between each of the listed items

	--> "name_of_some_file.txt"

	set text item delimiters to storedDelimiters
	-- restore the value of AppleScript's text item delimiters
	-- to whatever they were on entering the subroutine

	currentText
	-- return the modified text

end switchText

-------------

Hope that helps to clarify things a little. :-)

---
kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Replace slash by underscroe in file name
      • From: Paul Berkowitz <email@hidden>
References: 
 >Replace slash by underscroe in file name (From: stephan <email@hidden>)
 >Re: Replace slash by underscroe in file name (From: kai <email@hidden>)
 >Re: Replace slash by underscroe in file name (From: Christian Vinaa <email@hidden>)

  • Prev by Date: Re: Replace slash by underscroe in file name
  • Next by Date: Re: Replace slash by underscroe in file name
  • Previous by thread: Re: Replace slash by underscroe in file name
  • Next by thread: Re: Replace slash by underscroe in file name
  • Index(es):
    • Date
    • Thread