getting a list of labels from a record?
getting a list of labels from a record?
- Subject: getting a list of labels from a record?
- From: Alex Hall <email@hidden>
- Date: Mon, 27 May 2013 21:04:36 -0400
Hi again all,
I have a handler to recursively sort a list of strings, returning a new list with the strings in descending order of length. I use it for my templating handler. The templates work like this:
set network to "Linksys"
set signalStrength to "-69"
set template to "You are connected to $network at $signalStrength DbM"
set template to str_replace({"$network", "$signalStrength"}, {network, signalStrength}, template)
display dialog template --> You are connected to Linksys at -69 DbM
The problem is that, if one keyword were the same as the start of another, that smaller one might get replaced first and so the larger one would then be partially over-written and therefore not replaced. By ensuring that the largest string is replaced first, then the next smallest and so on, I can avoid the problem.
Now, the reason for my email: in order for the template handler (str_replace, but it needs a better name) to work, it has to have the list of keywords, and the list of their replacements, presented in the exact same order, so keyword[i] is replaced by keywordReplacements[i]. Obviously, once I sort the keywords list, the order is gone, and sorting the replacements list will not help since the order is likely going to come out different. I can make my sorting function return a record, where each label is the old index in the original list and the value is the word. Finally, the problem: despite much searching, I cannot find a way to get a list of the labels from a record. Python will illustrate my intent best:
for i in keywords.keys():
newReplacements.append(keywordReplacements[i])
#end for
In AS, I'd love to just do a similar thing:
repeat with i in (labels of keywords)
set newReplacements to newReplacements & (item i of keywordReplacements)
end repeat
I hope all my rambling has made sense. Bottom line: can I retrieve just the labels of a record as a list? Yes, a record can be cast to a list, but the labels are destroyed, and I need them to remain as their own list.
Have a great day,
Alex (msg sent from Mac Mini)
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden