Sunday, May 12, 2013

NSString commonPrefixWithString options example ios


commonPrefixWithString: options:

Returns a string containing characters the receiver and a given string have in common, starting from the beginning of each up to the first characters that aren’t equivalent.
- (NSString *)commonPrefixWithString:(NSString *)aString options:(NSStringCompareOptions)mask
Parameters
aString
The string with which to compare the receiver.
mask
Options for the comparison. The following search options may be specified by combining them with the C bitwiseOR operator: NSCaseInsensitiveSearchNSLiteralSearch. See String Programming Guide for details on these options.
Return Value of [NSString commonPrefixWithString options]
A string containing characters the receiver and aString have in common, starting from the beginning of each up to the first characters that aren’t equivalent.
Discussion of [NSString commonPrefixWithString options]
The returned string is based on the characters of the receiver. For example, if the receiver is “Ma¨dchen” and aStringis “Mädchenschule”, the string returned is “Ma¨dchen”, not “Mädchen”.
Example of [NSString commonPrefixWithString options]
- (NSString *)comboBox:(NSComboBox *)comboBox completedString:(NSString *)partialString
{
    for (NSString dataString in dataSourceArray) {
        if ([[dataString commonPrefixWithString:partialString options:NSCaseInsensitiveSearch] length] == [commonPrefixWithString:partialString length]) {
            return testItem;
        }
    }
    return @"";
}