AppleScript delimiters

[delimiters] whitespaceAndNewlineCharacterSet タブや改行文字で区切る(AppleScript-ObjC)

注意Windows改行のメタ文字\r\nを使うと2回区切りとなります



#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
property refNSArray : a reference to refMe's NSArray
property refNSString : a reference to refMe's NSString
property refNSCharacterSet : a reference to refMe's NSCharacterSet

###テキスト
set strSmapleText to "美しい\t日本語\nかも\r\nしれ\rない" as text
log class of strSmapleText -->(*text*)

###NSString
set ocidNoString to refNSString's stringWithString:strSmapleText
log ocidNoString as text
log className() of ocidNoString as text
(*__NSCFString*)

###NSCharacterSet(このセットは改行とタブ)
set ocidCharacterSet to refNSCharacterSet's whitespaceAndNewlineCharacterSet
log className() of ocidCharacterSet as text
(*__NSCFCharacterSet*)

###NSCharacterSetで区切る
set ocidNoArrayM to ocidNoString's componentsSeparatedByCharactersInSet:ocidCharacterSet
log ocidNoArrayM as list -->(*美しい, 日本語, かも, , しれ, ない*)
log className() of ocidNoArrayM as text
(*__NSArrayM*)

(*
英数字大文字小文字数字等
alphanumericCharacterSet
大文字
capitalizedLetterCharacterSet
制御文字(タブや改行を含む)
controlCharacterSet
小数点
decimalDigitCharacterSet
アクセント記号等
decomposableCharacterSet
全角?
illegalCharacterSet
文字のみ?
letterCharacterSet
小文字
lowercaseLetterCharacterSet
基本文字セット外の文字
nonBaseCharacterSet
句読点カンマ
punctuationCharacterSet
シンボル
symbolCharacterSet
大文字
uppercaseLetterCharacterSet
タブと改行
whitespaceAndNewlineCharacterSet
タブ
whitespaceCharacterSet
*)

|

[delimiters] whitespaceCharacterSet タブ文字で区切る(AppleScript-ObjC)

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
property refNSArray : a reference to refMe's NSArray
property refNSString : a reference to refMe's NSString
property refNSCharacterSet : a reference to refMe's NSCharacterSet

###テキスト
set strSmapleText to "美しい日本語\tかもしれない" as text
log class of strSmapleText -->(*text*)

###NSString
set ocidNoString to refNSString's stringWithString:strSmapleText
log ocidNoString as text -->(*美しい日本語かもしれない*)
log className() of ocidNoString as text
(*__NSCFString*)

###NSCharacterSet(このセットはタブ)
#Unicode General Category Zs
#CHARACTER TABULATION (U+0009)
set ocidCharacterSet to refNSCharacterSet's whitespaceCharacterSet
log className() of ocidCharacterSet as text
(*__NSCFCharacterSet*)

###NSCharacterSetで区切る
set ocidNoArrayM to ocidNoString's componentsSeparatedByCharactersInSet:ocidCharacterSet
log ocidNoArrayM as list -->(*美しい日本語, かもしれない*)
log className() of ocidNoArrayM as text
(*__NSArrayM*)

(*
英数字大文字小文字数字等
alphanumericCharacterSet
大文字
capitalizedLetterCharacterSet
制御文字(タブや改行を含む)
controlCharacterSet
小数点
decimalDigitCharacterSet
アクセント記号等
decomposableCharacterSet
全角?
illegalCharacterSet
文字のみ?
letterCharacterSet
小文字
lowercaseLetterCharacterSet
基本文字セット外の文字
nonBaseCharacterSet
句読点カンマ
punctuationCharacterSet
シンボル
symbolCharacterSet
大文字
uppercaseLetterCharacterSet
タブと改行
whitespaceAndNewlineCharacterSet
タブ
whitespaceCharacterSet
*)

|

[delimiters]改行やタブで区切る(paragraphs 段落で区切る)


set strSmapleText to "美しい日本語 かもしれない" as text
log (count paragraphs of strSmapleText) -->(*1*)

###メタ文字(タブ)-->\t
set strSmapleText to "美しい日本語\tかもしれない" as text
log (count paragraphs of strSmapleText) -->(*1*)

###メタ文字(マック改行CR)-->\r
set strSmapleText to "美しい日本語\rかもしれない" as text
log (count paragraphs of strSmapleText) -->(*2*)

###メタ文字(unix改行LF)-->\n
set strSmapleText to "美しい日本語\nかもしれない" as text
log (count paragraphs of strSmapleText) -->(*2*)

###メタ文字(Windows改行CRLF)-->\r\n
set strSmapleText to "美しい日本語\r\nかもしれない" as text
log (count paragraphs of strSmapleText) -->(*2*)

set AppleScript's text item delimiters to "\r\n"

set listSmapleText to text items in strSmapleText
log listSmapleText -->(*美しい日本語, かもしれない*)
log class of listSmapleText -->(*list*)

set AppleScript's text item delimiters to ""

|

[delimiters] componentsSeparatedByCharactersInSet  (AppleScript-ObjC)

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
property refNSArray : a reference to refMe's NSArray
property refNSString : a reference to refMe's NSString
property refNSCharacterSet : a reference to refMe's NSCharacterSet

###テキスト
set strNO to "090-123-45-67-89" as text
log class of strNO -->(*text*)

###NSString
set ocidNoString to refNSString's stringWithString:strNO
log ocidNoString as text -->(*090-123-45-67-89*)
log className() of ocidNoString as text
(*__NSCFString*)

###NSCharacterSet-で作って
set ocidCharacterSet to refNSCharacterSet's characterSetWithCharactersInString:"-"
log className() of ocidCharacterSet as text
(*__NSCFCharacterSet*)

###NSCharacterSetで区切る
set ocidNoArrayM to ocidNoString's componentsSeparatedByCharactersInSet:ocidCharacterSet
log ocidNoArrayM as list -->(*090, 123, 45, 67, 89*)
log className() of ocidNoArrayM as text
(*__NSArrayM*)



#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
property refNSArray : a reference to refMe's NSArray
property refNSString : a reference to refMe's NSString
property refNSCharacterSet : a reference to refMe's NSCharacterSet

###テキスト
set strNO to "090-123x45-67x89" as text
log class of strNO -->(*text*)

###NSString
set ocidNoString to refNSString's stringWithString:strNO
log ocidNoString as text -->(*090-123x45-67x89*)
log className() of ocidNoString as text
(*__NSCFString*)

###NSCharacterSet-で作って
set ocidCharacterSet to refNSCharacterSet's characterSetWithCharactersInString:"x,-"
log className() of ocidCharacterSet as text
(*__NSCFCharacterSet*)

###NSCharacterSetで区切る
set ocidNoArrayM to ocidNoString's componentsSeparatedByCharactersInSet:ocidCharacterSet
log ocidNoArrayM as list -->(*090, 123, 45, 67, 89*)
log className() of ocidNoArrayM as text
(*__NSArrayM*)

|

[delimiters] componentsSeparatedByString  (AppleScript-ObjC)

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
property refNSArray : a reference to refMe's NSArray
property refNSString : a reference to refMe's NSString

###
set strNO to "090-123-45-67-89" as text
log class of strNO -->(*text*)

set ocidNoString to refNSString's stringWithString:strNO
log ocidNoString as text -->(*090-123-45-67-89*)
log className() of ocidNoString as text
(*__NSCFString*)

set ocidNoArrayM to ocidNoString's componentsSeparatedByString:"-"
log ocidNoArrayM as list -->(*090, 123, 45, 67, 89*)
log className() of ocidNoArrayM as text
(*__NSArrayM*)

|

[delimiters] リストの『カンマ』を残してテキストに

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application

###現在の区切り文字は?
log AppleScript's text item delimiters
-->(**)

###テキスト
set strNO to "090-123-45-67-89" as text
log strNO
log class of strNO -->(*text*)

###区切り文字指定
set AppleScript's text item delimiters to {"-"}

###↑ここの区切り文字で区切りなさい
set listNO to text items in strNO
log listNO
log class of listNO -->(*list*)
-->(*090, 123, 45, 67, 89*)<--この時点ではリスト形式

###区切り文字指定
set AppleScript's text item delimiters to {","}
###区切り文字でテキスト化
set listNOList to text items in listNO as text
log listNOList
log class of listNOList -->(*text*)
-->(*090,123,45,67,89*)<--テキスト形式

|

[delimiters] 区切り文字を複数してい

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application

###現在の区切り文字は?
log AppleScript's text item delimiters
-->(**)

###テキストに全半角混在の場合(ハイフンとスペース)
set strNO to "090ー123-45 67 89" as text
log strNO
log class of strNO -->(*text*)

###区切り文字指定(複数してい)
set AppleScript's text item delimiters to {"ー", "-", " ", " "}

###↑ここの区切り文字で区切りなさい
set listNO to text items in strNO
log listNO
log class of listNO -->(*list*)
-->(*090, 123, 456, 7, 89*)

|

[delimiters] text items in(テキストを区切り文字でリスト化)

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application

###現在の区切り文字は?
log AppleScript's text item delimiters
-->(**)

###典型的なテキスト
set strNO to "090-1234-56789" as text
log strNO
log class of strNO -->(*text*)

###区切り文字指定
set AppleScript's text item delimiters to "-"

###↑ここの区切り文字で区切りなさい
set listNO to text items in strNO
log listNO
log class of listNO -->(*list*)
-->(*090, 1234, 56789*)

|

[delimiters] delimiters 区切り文字

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application

###現在の区切り文字は?
log AppleScript's text item delimiters
-->(**)

###典型的なリストArray形式
set listNO to {"090", "1234", "56789"} as list
log listNO
log class of listNO -->(*list*)

###区切り文字指定
set AppleScript's text item delimiters to "-"

###区切り文字を使ってテキスト化しなさい
set strList to listNO as text
log strList
log class of strList -->(*text*)
-->(*090-1234-56789*)

###区切り文字指定
set AppleScript's text item delimiters to "×"

###区切り文字を使ってテキスト化しなさい
set strList to listNO as text
log strList
log class of strList -->(*text*)
-->(*090×1234×56789*)

###最後に戻す
set AppleScript's text item delimiters to ""


#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application

###現在の区切り文字は?
log text item delimiters
-->(**)

###典型的なリストArray形式
set listNO to {"090", "1234", "56789"} as list
log listNO
log class of listNO -->(*list*)

###区切り文字指定
set text item delimiters to {"-"}

###区切り文字を使ってテキスト化しなさい
set strList to listNO as text
log strList
log class of strList -->(*text*)
-->(*090-1234-56789*)

###区切り文字指定
set text item delimiters to {"×"}

###区切り文字を使ってテキスト化しなさい
set strList to listNO as text
log strList
log class of strList
-->(*090×1234×56789*)

###最後に戻す
set text item delimiters to {""}

|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat BookMark Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat Sequ Acrobat Sign Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe RemoteUpdateManager Apple AppleScript AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Audio AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript Guide AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript Mail AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFileManager enumeratorAtURL AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Events Plist AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML savedSearch AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript XMP AppleScript YouTube AppleScript Zero Suppress Applications CityCode Design github iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom