在 Applescript 中获取部分字符串 [英] Get part of string in Applescript

查看:36
本文介绍了在 Applescript 中获取部分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试制作一个 Applescript,它可以读取文件夹中的文件并且只使用文件名的一部分.这些文件看起来像这样:the.name.of.a.tv.show.s01e01

I try to make a applescript that read files in a folder and takes only part of the filename. The files would look like this: the.name.of.a.tv.show.s01e01

我可以搜索 s01,但我必须为每个可能到来的季节制定规则.

I could search for s01 but then i have to make a rule for every season that can come.

有什么办法可以先查找 s--e-- 然后再取文件名的一部分吗?

Is there some way to look for s--e-- and then take the part of the filename before that?

推荐答案

尝试:

set xxx to "the.name.of.a.tv.show.s01e01 etc etc"
set yyy to (do shell script "echo " & xxx & " | sed 's/.s[0-9][0-9]e[0-9][0-9].*//'")
return yyy

结合您之前的问题:

set seasonList to {}
repeat with aShow in listOfShows
set aShow to aShow as string
set end of seasonList to (do shell script "echo " & aShow & " | sed 's/.s[0-9][0-9]e[0-9][0-9].*//'")
end repeat
return seasonList

这篇关于在 Applescript 中获取部分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆