Previous Index Next

BridgePlus.framework, SMSForder Class Methods

Category

List manipulation methods

Method

arrayByMergingTextAtIndexes:inArray:inserting:error:

Summary

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.

Signature

+ (NSArray *)arrayByMergingTextAtIndexes:(NSArray *)mergingIndexes inArray:(NSArray *)listOrArray inserting:(NSString *)separatorString error:(NSError *__autoreleasing *)outError

Parameters

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

Result

The resulting array

Availability

Version 1.0.0

Notes

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.

Sample

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.


Click here to open script in a script editor