AppleScript 文本分隔符
AppleScript Text delimiter
我收到一份包含多行的报告,例如:
第 1 行 20170719-5749-MMFF1FHDKS-23
第 2 行 20170717-5749-MMYG8GBTGK-23
第 3 行 20170719-5749-ML2Y7HYLJ3-9
我想提取每个 MMFF1FHDKS、MMYG8GBTGK、ML2Y7HYLJ3 等,将它们添加到数组中,并以这种格式的文本形式添加到剪贴板中:
MMFF1FHDKS、MMYG8GBTGK、ML2Y7HYLJ3
我知道我必须使用文本定界符,但我怎样才能得到这个随机值?
请注意,数字并不总是相同,行数是随机的,发件人无法更改报告的格式。
假设每行中始终有 3 个连字符,并且请求的字符串正好在您可以使用的最后一个连字符之前
set theRows to "20170719-5749-MMFF1FHDKS-23
20170717-5749-MMYG8GBTGK-23
20170719-5749-ML2Y7HYLJ3-9"
set theResult to {}
set {TID, text item delimiters} to {text item delimiters, "-"}
repeat with row in (get paragraphs of theRows)
set end of theResult to text item 3 of row
end repeat
set text item delimiters to ", "
set the clipboard to theResult as text
set text item delimiters to TID
我收到一份包含多行的报告,例如:
第 1 行 20170719-5749-MMFF1FHDKS-23
第 2 行 20170717-5749-MMYG8GBTGK-23
第 3 行 20170719-5749-ML2Y7HYLJ3-9
我想提取每个 MMFF1FHDKS、MMYG8GBTGK、ML2Y7HYLJ3 等,将它们添加到数组中,并以这种格式的文本形式添加到剪贴板中:
MMFF1FHDKS、MMYG8GBTGK、ML2Y7HYLJ3
我知道我必须使用文本定界符,但我怎样才能得到这个随机值?
请注意,数字并不总是相同,行数是随机的,发件人无法更改报告的格式。
假设每行中始终有 3 个连字符,并且请求的字符串正好在您可以使用的最后一个连字符之前
set theRows to "20170719-5749-MMFF1FHDKS-23
20170717-5749-MMYG8GBTGK-23
20170719-5749-ML2Y7HYLJ3-9"
set theResult to {}
set {TID, text item delimiters} to {text item delimiters, "-"}
repeat with row in (get paragraphs of theRows)
set end of theResult to text item 3 of row
end repeat
set text item delimiters to ", "
set the clipboard to theResult as text
set text item delimiters to TID