Let say I have this in my clipboard :
************TH4F fsdfssdggg0878 Ex.US Unknown 0 $100.00 05/24/17 04:40 No Bonus
************TH4F fsdfssdggg0878 Un.UK Unknown 0 $50.00 05/20/17 04:44 No Bonus
who can I only keep the total and add it in a list and same for the date ?
I'm a bit stuck on the script for now :
repeat with i in (get (the clipboard)'s text items)
return i
end repeat
Best Answer
You can't really (or shouldn't) use
text items
without first defining yourtext item delimiters
.If each field in the formatted text is separated by a tab character, then the task is trivial:
If the fields are, as they appear here, actually separated by a variable number of spaces, then one might be tempted to count each space between each field, and enumerate the text items in the same way we just did above. However, this is impractical, and more importantly, it is not a very robust way to approach this in a general context, because the content of your data might change slightly at some point. For example, you may, on one occasion, select the text flush with the start of the line, whilst on another occasion, over-select and include some leading whitespace.
One way to ensure consistency is to deal with the spaces first:
Now
cb
contains an homogeneously-delimited version of your clipboard data, where each field is separated by a single space character. Now we can employ the same technique from earlier, and obtain the relevanttext items
. Without changing yourtext item delimiters
, which will currently be set tospace
: