Sunday, January 21, 2018

#1 2003-07-06 12:08:33 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Strip Diacritcals

This script will convert letters with diacriticals (accent marks) in a string to the letters with no diacriticals.

OS version: Any

Applescript:

property letters_dia_uc : (characters of "ÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜŸ")
property letters_dia_lc : (characters of "áàâäãåçéèêëíìîïñóòôöõúùûüÿ")
property letters_nondia_uc : (characters of "AAAAAACEEEEIIIINOOOOOUUUUY")
property letters_nondia_lc : (characters of "aaaaaaceeeeiiiinooooouuuuy")

set the_string to "This is some text. ÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜŸáàâäãåçéèêëíìîïñóòôöõúùûüÿ"
return strip_diacriticals(the_string)

on strip_diacriticals(the_string)
   set search_chars to letters_dia_uc & letters_dia_lc
   set replace_chars to letters_nondia_uc & letters_nondia_lc
   set return_string to ""
   repeat with i from 1 to (count of characters of the_string)
       set string_char to (character i of the_string)
       considering case
           if search_chars contains string_char then
               repeat with j from 1 to (count of search_chars)
                   if (item j of search_chars) = string_char then
                       set return_string to return_string & (item j of replace_chars)
                       exit repeat
                   end if
               end repeat
           else
               set return_string to return_string & string_char
           end if
       end considering
   end repeat
   return return_string as string
end strip_diacriticals


One mans trash is another mans treasure

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)