NSString_InstanceMethods

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

NSComparisonResult

These constants are used to indicate how items in a request are ordered.

enum {
NSOrderedAscending = -1,
NSOrderedSame,
NSOrderedDescending
};
typedef NSInteger NSComparisonResult;

更多相关文章
一周排行
  • 提示:定义函数可以求阶乘,再定义函数求阶乘之和.1和0的阶乘是1,n(n > 1)的阶乘是n * (n-1) * (n - 2) * … * 1 //采用了函数嵌套调用和函数递归调用 1 //求解阶乘 2 in ...
  • 幫朋友做点东西,就是读取时时彩的数据源信息. 第一次使用vs2012 , 顺便学习一下.net \ c# \ silverlight \ WCF . 感想: 1. VS越做越庞大,速度越来越慢.开发成本越来越高,一点
  •     /**       * 生成数据文件      *       * @param filePath 写入文件的路径      * @param content 写入的字符串内容      * @return 
  • inflector(辅助) 将用户输入的字符串转化成驼峰或者空格或者底线的小插件; 这个是一个小的过滤器, 平常也是用不到的, 合格是过滤器的代码: app.filter("inflector", ...
  • 这道题开始用链表来做,遍历之后有序插入,经常new对象,而且一开始next指针没有设置为null导致了一直runtime error,后来发现这个问题后,就很悲催的Time Limit Exceeded,可能是遍历链
  • 赋闲脱产的半年里,自己用C++/Java/Lisp胡乱写了几万行的代码,到了现在的公司,给OpenStack项目贴牛皮藓,反倒是Python用得最多.作为公司里面唯一的Emacser(没准也是 公司里JJ最长的吧,笑
  • 201. Orchard学习 一.基础 210. Orchard学习 二.启动 211. Orchard学习 二 1.Application_Start 212. Orchard学习 二 2.ManualResetE
  • HDU 1712 ACboy needs your help(包背包) pid=1712">http://acm.hdu.edu.cn/showproblem.php?pid=1712 题意:     ...
  • 最近想写点自动化小工具, 提高点windows操作系统生活的品质, 于是我找到python,找到python的两个比较好的资料, 第一个是python语言特性的入门 http://www.pyth ontab.com
  • 基于涛哥shiro案例16 的这时候要配置service方法的缓存 在spring-config.xml添加 <context:annotation-config /> <cache:annotat ...