• 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
Rép: Reformatting a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Rép: Reformatting a string


  • Subject: Rép: Reformatting a string
  • From: KOENIG Yvan <email@hidden>
  • Date: Sat, 28 Jan 2012 16:01:51 +0100

As long as the languages aren’t corrected, I will use :

set texte to "Hello happy tax payers"
set texte2 to ""
repeat with unCarac in text of texte
set unID to id of unCarac
if (unID > 47) and unID < 127 then
set texte2 to texte2 & character id (65296 - 48 + unID)
else
set texte2 to texte2 & unCarac
end if
end repeat
set the clipboard to texte2 & "ß"

my changeCase(the clipboard as text, "upper")
set the clipboard to my supprime(result, ":")

--=====
(*
removes every occurences of d in text t
*)
on supprime(t, d)
local oTIDs, l
set oTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end supprime

--=====
(*
Le second argument peut être: "upper", "lower", "title", "capitalize"
*)

on changeCase(txt, mode)
set python_script to "import sys; print sys.argv[1].decode('utf8')." & mode & "().encode('utf8')"
set maybe to do shell script "/usr/bin/python -c " & quoted form of python_script & " " & quoted form of txt
if mode is "upper" and maybe contains "ß" then
set oTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to "ß"
set l to text items of maybe
set AppleScript's text item delimiters to character id 7838
set maybe to "" & l
set AppleScript's text item delimiters to oTIDs
end if
return maybe
end changeCase

--=====

This simple patch can't be used to the two other languages because the script can't decide if an available SS is a sadly uppercased ß or if it's a couple of S.
I'm a bit surprised to see that the most recent Python available in my copy of Lion 10.7.2 is version 2.7 when there is an official version 3.2.2 released on September 4th, 2011.

Yvan KOENIG (VALLAURIS, France) samedi 28 janvier 2012 15:46:04



 _______________________________________________
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

  • Follow-Ups:
    • Re: Rép: Reformatting a string
      • From: Thomas Fischer <email@hidden>
  • Prev by Date: Re: Reformatting a string
  • Next by Date: Re: Reformatting a string
  • Previous by thread: Re: Reformatting a string
  • Next by thread: Re: Rép: Reformatting a string
  • Index(es):
    • Date
    • Thread