Is there a way to make more than one symbol a delimiter? Like “,” & “:” at the same time?
2, Can you tell a delimiter where to start and stop? For example. If the delimiter is “:” and I have
:sdfgdgd,fgdjhh: I will get “sdfgdgd,fgdjhh”. What if I want to stop at the “,” so that I get “sdfgdgd”? Is this possible?
set a to "cat:dog cow,bat:frog"
set text item delimiters to ":"
set a to text items of a --> {"cat", "dog cow,bat", "frog"}
set text item delimiters to ","
set a to a as string --> "cat,dog cow,bat,frog"
set a to text items of a
a --> {"cat", "dog cow", "bat", "frog"}
Yes
set a to ">>some text <find this statement> <more text>"
set text item delimiters to "<"
set a to text items 2 thru -1 of a as string --> "find this statement> <more text>"
set text item delimiters to ">"
set a to first text item of a
a --> "find this statement"
Here are some handlers that I often use to extract text:
on extractIdentifier(inputText, identifierText, startText, endText)
set text item delimiters to identifierText
set inputText to text items 2 thru -1 of inputText as string
-- call extractBetween() to do the rest of the extracting
extractBetween(inputText, startText, endText)
end extractIdentifier
on extractBetween(inputText, startText, endText)
set text item delimiters to startText
set inputText to text items 2 thru -1 of inputText as string
set text item delimiters to endText
first text item of inputText
end extractBetween
set a to "name: 'bob', email: 'bob@site.com', phone number: '1234'"
extractIdentifier(a, "email", "'", "'")
--> "bob@site.com"
This topic appears to have something in common with the discussion about troubles delimiting. If you’re trying to slice a string from within a bunch of other text, you can also achieve it with ‘offset’:
set t to "more.info.from:http://www.myspace.com.23.true"
t's text (offset of "http:" in t) thru ((offset of ".com" in t) + 3) --> "http://www.myspace.com"