Previous | Index | Next |
List manipulation methods
arrayByMergingTextAtIndexes:inArray:inserting:error:
Concatenate two text items into one. Provide a list of two consecutive (zero-based) indexes of the items to merge; they will be joined using the separator in the order provided, and appear at the first of the indexes. Empty strings will be ignored.
+ (NSArray *)arrayByMergingTextAtIndexes:(NSArray *)mergingIndexes inArray:(NSArray *)listOrArray inserting:(NSString *)separatorString error:(NSError *__autoreleasing *)outError
mergingIndexes = a list of two consecutive (zero-based) indexes of the items to merge
listOrArray = an array or list (items to merge must be strings)
separatorString = the string to insert between the merged items
outError = missing value or reference
The resulting array
Version 1.0.0
If you set outError to reference, the result will be a list of two items. If there is no error, the first item will be the result of the method and the second will be missing value. If there is an error, the first item will be missing value and the second item with be an NSError.
use scripting additions
use framework "Foundation"
use script "BridgePlus"
load framework
set listOrArray to {"apples", "oranges", "lemons", "peaches"}
set theIndexes to {1, 2}
set toInsert to " and "
set theResult to current application's SMSForder's arrayByMergingTextAtIndexes:theIndexes inArray:listOrArray inserting:toInsert |error|:(missing value)
ASify from theResult
--> {"apples", "oranges and lemons", "peaches"}
theResult as list
--> {"apples", "oranges and lemons", "peaches"}
set theIndexes to {3, 4}
set {theResult, theError} to current application's SMSForder's arrayByMergingTextAtIndexes:theIndexes inArray:listOrArray inserting:toInsert |error|:(reference)
if theResult = missing value then error (theError's localizedDescription() as text)
--> error number -2700 At least one of the merge indexes is out of range or otherwise invalid.