Loops 如何使用AppleScript枚举文章的段落?
一个月以来我一直在拼命寻找解决方案,请帮帮我 下面是我试图修改的文章的一个示例: “这是导言 这是一些案文的第1段 这是一些案文的第2段 这是一些案文的第3段 这是某些案文的第4段 这是一些案文的第5段 这是奥特罗“ 我想做的是列举这篇文章的每一段,让这篇文章看起来像这样: “这是导言Loops 如何使用AppleScript枚举文章的段落?,loops,applescript,Loops,Applescript,一个月以来我一直在拼命寻找解决方案,请帮帮我 下面是我试图修改的文章的一个示例: “这是导言 这是一些案文的第1段 这是一些案文的第2段 这是一些案文的第3段 这是某些案文的第4段 这是一些案文的第5段 这是奥特罗“ 我想做的是列举这篇文章的每一段,让这篇文章看起来像这样: “这是导言 这是一些案文的第1段 这是一些案文的第2段 这是一些案文的第3段 这是某些案文的第4段 这是一些案文的第5段 这是奥特罗” 有可能吗?简单的解决方案,它跳过第一段和最后一段,并将序号添加到其他段落,即索引号-1
有可能吗?简单的解决方案,它跳过第一段和最后一段,并将序号添加到其他段落,即索引号-1 结果收集在一个列表中,并在末尾用
文本项分隔符连接起来
set theText to "This is introduction.
This is paragraph 1 of some text.
This is paragraph 2 of some text.
This is paragraph 3 of some text.
This is paragraph 4 of some text.
This is paragraph 5 of some text.
This is outro"
set paragraphsOfText to paragraphs of theText
set paragraphList to {first item of paragraphsOfText, ""}
set counter to 1
repeat with i from 2 to ((count paragraphsOfText) - 1)
set currentItem to item i of paragraphsOfText
if length of currentItem is not 0 then
set end of paragraphList to (counter as text) & ". " & currentItem
set counter to counter + 1
end if
end repeat
set end of paragraphList to ""
set end of paragraphList to last item of paragraphsOfText
set {TID, text item delimiters} to {text item delimiters, return}
set theResult to paragraphList as text
set text item delimiters to TID
display dialog theResult
谢谢你,先生。我要试试:)这很管用。如果段落之间用回车隔开怎么办?这实际上是我的情况…我在5分钟前更新了答案并添加了返回谢谢:)但是文本中的段落没有间隔返回,所以当我尝试放置返回时,输出更改…我的文本在文件中。。。对不起,我应该先说这个