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 {""}

|

その他のカテゴリー

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