首页 > 解决方案 > 在 Applescript 中删除部分字符串

问题描述

所以我有一个字符串,但我只想要它在某个部分之后。我知道您最好在 shell 中执行此操作,所以我尝试了,但我有限的 shell 知识并没有让我走得更远。这篇文章试图做类似的事情,但不完全是我需要的。

set theString to "hello/world"
do shell script "echo " & theString & "???"
return theString --the output should be hello

标签: shellapplescript

解决方案


不需要 shell 脚本。获取斜杠在字符串中的位置,返回子串从头到尾的位置 - 1

set theString to "hello/world"
set slashIndex to offset of "/" in theString
return text 1 thru (slashIndex - 1) of theString

推荐阅读