您好,登錄后才能下訂單哦!
NSString
Inherits from: NSObject
Conforms to: NSObject, NSMutableCopying, NSSecureCoding, NSCopying
stringByTrimmingCharactersInSet:
Returns a new string made by removing from both ends of the receiver characters contained in a given character set.
- (NSString *)stringByTrimmingCharactersInSet:(NSCharacterSet *)set
Parameters
set
A character set containing the characters to remove from the receiver. set must not be nil.
Return Value
A new string made by removing from both ends of the receiver characters contained in set. if the receiver is composed entirely of characters from set, the empty string is returned.
Discussion
Use whitespaceCharacterSet or whitespaceAndNewlineCharacterSet to remove whitespace around strings.
rangeOfString:
Finds and returns the range of the first occurrence of a given string within the receiver.
- (NSRange)rangeOfString:(NSString *)aString
Parameters
aString
The string to search for. This value must not be nil.
Raises an NSInvalidArgumentException if aString is nil.
Return Value
An NSRange structure giving the location and length in the receiver of the first occurrence of aString. Returns {NSNotFound, 0} if aString is not found or is empty (@“”).
e.g.
NSRange *range = [“http://unpbook.com/small.git” rangeOfString:@“://”];
log:range.location = 4,length = 3
Discussion
Invokes rangeOfString:options: with no options.
compare:options:
Compares the string with the specified string using the given options.
- (NSComparisonResult)compare:(NSString *)aString options:(NSStringCompareOptions)mask
Parameters
aString
The string with which to compare the receiver.
This value must not be nil. If this value is nil, the behavior is undefined and may change in future versions of OS X.
mask
Options for the search—you can combine any of the following using a C bitwise OR operator: NSCaseInsensitiveSearch, NSLiteralSearch, NSNumericSearch. See String Programming Guide for details on these options.
NSCaseInsensitiveSearch 不區(qū)分大小寫
NSLiteralSearch 區(qū)分大小寫
NSNumericSearch 只比較字符串的個數(shù),而不比較字符串的字面值
Return Value
The result of invoking compare:options:range: with a given mask as the options and the receiver’s full extent as the range.
Discussion
If you are comparing strings to present to the end-user, you should typically use localizedCompare: or localizedCaseInsensitiveCompare: instead, or use compare:options:range:locale: and pass the user’s locale.
e.g.
NSString *scheme;
if ([scheme compare:@"http"] options:NSCaseInsensitiveSearch] == NSOrderedSame)
additional
enum { NSOrderedAscending = -1, NSOrderedSame, NSOrderedDescending }; typedef NSInteger NSComparisonResult;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。