A Replace() function
A Replace() function
- Subject: A Replace() function
- From: Emile Schwarz <email@hidden>
- Date: Wed, 18 Aug 2010 10:41:21 +0200
Hi all,
I needed a Replace() function to replace colon by dash and I failed to
found it in the language.
So I searched in the Internet and found:
http://foolsworkshop.com/applescript/2008/05/an-applescript-replace-text-method/
I was not happy with that and wrote my own one (below).
Is it correct (it looks like that)?
TIA,
Emile
-- Syntax:
-- Result = Replace(SourceString, OldString, NewString)
--
on Replace(SourceStr, OldStr, NewStr)
set LoopIdx to 1
set NewSource to ""
set SourceLen to count of SourceStr
repeat SourceLen times
set aChar to character LoopIdx of SourceStr
if aChar = OldStr then
set NewSource to NewSource & NewStr
else
set NewSource to NewSource & aChar
end if
set LoopIdx to LoopIdx + 1
end repeat
return NewSource
end Replace
-- Displays the time without colons
get Replace("10:28:35", ":", "-")
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden