带有 Applescript 的标题大小写
Title Case with Applescript
我有一个标题大写的字符串,但文章应该小写。我正在尝试将文章更改为小写。这是我现在拥有的:
set theStringTitleCase to "Iranian General Killed In Syria"
set theListTitleCase to every word of theStringTitleCase
set articles_in_title to {"in", "to", "at"}
set fixed_words_in_title to {}
repeat with the_word in theListTitleCase
repeat with the_article in articles_in_title
if the_word contains the_article then
set the end of fixed_words_in_title to the_article
else
set the end of fixed_words_in_title to the_word
end if
end repeat
end repeat
set theStringTitleCase to fixed_words_in_title as string
return theStringTitleCase
不确定我哪里错了
这应该可以解决问题。
set theStringTitleCase to "Iranian General Killed In Syria"
set lowerCasedArticles to small_articles(theStringTitleCase)
log lowerCasedArticles
--> (*Iranian General Killed in Syria*)
to small_articles(aString)
set capArticles to {" In ", " To ", " At "} # spaces are mandatory!
set smallArticles to {" in ", " to ", " at "}
# fail early conditions . . .
if (count capArticles) ≠ (count smallArticles) then error "unequal number of elements in lists "
if aString is "" then return ""
# we replace capitalized articles with lower cased ones below.
tell (a reference to my text item delimiters)
set tids to contents of it
repeat with i from 1 to (count capArticles)
set contents of it to item i of capArticles
set oldlist to text items of aString
set contents of it to item i of smallArticles
set aString to oldlist as string
end repeat
set contents of it to tids
return aString
end tell
end small_articles
我有一个标题大写的字符串,但文章应该小写。我正在尝试将文章更改为小写。这是我现在拥有的:
set theStringTitleCase to "Iranian General Killed In Syria"
set theListTitleCase to every word of theStringTitleCase
set articles_in_title to {"in", "to", "at"}
set fixed_words_in_title to {}
repeat with the_word in theListTitleCase
repeat with the_article in articles_in_title
if the_word contains the_article then
set the end of fixed_words_in_title to the_article
else
set the end of fixed_words_in_title to the_word
end if
end repeat
end repeat
set theStringTitleCase to fixed_words_in_title as string
return theStringTitleCase
不确定我哪里错了
这应该可以解决问题。
set theStringTitleCase to "Iranian General Killed In Syria"
set lowerCasedArticles to small_articles(theStringTitleCase)
log lowerCasedArticles
--> (*Iranian General Killed in Syria*)
to small_articles(aString)
set capArticles to {" In ", " To ", " At "} # spaces are mandatory!
set smallArticles to {" in ", " to ", " at "}
# fail early conditions . . .
if (count capArticles) ≠ (count smallArticles) then error "unequal number of elements in lists "
if aString is "" then return ""
# we replace capitalized articles with lower cased ones below.
tell (a reference to my text item delimiters)
set tids to contents of it
repeat with i from 1 to (count capArticles)
set contents of it to item i of capArticles
set oldlist to text items of aString
set contents of it to item i of smallArticles
set aString to oldlist as string
end repeat
set contents of it to tids
return aString
end tell
end small_articles