Sunday, December 4, 2022

#1 2005-10-21 05:32:45 am

From:: Malasaña, Madrid
Registered: 2002-11-20
Posts: 2014

How can I find specific characters in a text? (eg, numbers, capitals)

This FAQ applies to someone looking for special characters in a text. For example: numbers, capitals, accented characters, etc.

There is not a built-in function in AppleScript, so you should use any regexp tool (scripting addition or "do shell script" call) or ellaborate your own method depending on your needs.

In this quick example, we will delete all found numbers in a text:


stripNumbers("I'm the number 1.") --> "I'm the number ."

to stripNumbers(inputText)
   set theNumbers to "0123456789"
   set prevTids to AppleScript's text item delimiters
   repeat with i in theNumbers
       set AppleScript's text item delimiters to i
       set inputText to inputText's text items
       set AppleScript's text item delimiters to prevTids
       set inputText to inputText as text
   end repeat
end stripNumbers



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)