删除Applescript中的部分字符串 [英] Removing part of string in Applescript

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

问题描述

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

So I have a string but I only want it after a certain part. I know that you would optimally do this in shell so I tried, but my limited shell knowledge didn't bring me far. This post tries to do a similar thing but not exactly what I need.

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

推荐答案

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

There's no shell script needed. Get the position of the slash in the string and return the substring from the beginning to the position - 1

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

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

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