On 2015-03-20, isw <
i...@witzend.com> wrote:
[Followups set to alt.comp.lang.applescript]
> I opened one of the recipes with a hex editor, and found that the
> location of the slash contains "\u8260 ". A search revealed that is
> "&frasl" in HTML, which is evidently a "fraction slash". The Mac's
> Character Viewer thinks that "fraction slash" is U+0066, for what that
> is worth.
8260 decimal is 2044 hexadecimal. In AppleScript, you can use the «data
utxt» formatter to work with Unicode characters. To get the fraction
slash character, you can use:
«data utxt2044» as Unicode text
> So all I want to do is find the thing so it can be replaced by a
> "regular" slash, but I need to know what to tell the AppleScript to look
> for, and I don't know how to do that.
This seems to work for me:
-- begin script
property bunchOfText : "this ⁄ is a test
of the emergency ⁄ broadcast system
please stay ⁄ calm
and bring ⁄ your towel"
property searchCharacter : «data utxt2044» as Unicode text
set newText to my SearchReplace(bunchOfText, searchCharacter, "/")
return my SearchReplace(newText, searchCharacter, "***")
on SearchReplace(sourceStr, searchString, replaceString)
-- replace <searchString> with <replaceString> in <sourceStr>
set searchStr to (searchString as text)
set replaceStr to (replaceString as text)
set sourceStr to (sourceStr as text)
set saveDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to (searchString)
set theList to (every text item of sourceStr)
set AppleScript's text item delimiters to (replaceString)
set theString to theList as string
set AppleScript's text item delimiters to saveDelims
return theString
end SearchReplace
-- end script
The "bunchOfText" property is a string with the Unicode 2044 characters
in it (added directly from the keyboard by typing Option-Shift-1. I used
the «data utxt» formatter to set the "searchCharacter" property to the
single Unicode 2044 character so I can search for it. I typed the « and
» characters on the keyboard with Option-\ and Option-Shift-\,
respectively. The SearchReplace handler uses an AppleScript text item
delimiter trick to locate the substring and replace it.
--
E-mail sent to this address may be devoured by my ravenous SPAM filter.
I often ignore posts from Google. Use a real news client instead.
JR