您好,登錄后才能下訂單哦!
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 不區分大小寫
NSLiteralSearch 區分大小寫
NSNumericSearch 只比較字符串的個數,而不比較字符串的字面值
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;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。