标签:
1 #import <Foundation/Foundation.h>
2
3 int main(int argc, const char * argv[])
4 {
5 @autoreleasepool
6 {
7 /*
8 NSString *beijing = @"北京";
9 NSString *welcome = [beijing stringByAppendingString:@" 欢迎你 "];//字符串连接
10 NSLog(@"%@",welcome);
11 NSLog(@"%zi",welcome.length);//字符串的长度
12 BOOL flag = [beijing isEqualToString:@"北京"];//字符串比较
13 NSLog(@"%d",flag);
14 */
15 /*
16 NSString *number = @"123456",*floatNumber = @"1233.45";
17 float aa = [floatNumber floatValue];// 字符串转换成浮点型
18 int a = [number intValue];//字符串转换成整型
19 NSLog(@"%d,%f",a,aa);
20 */
21 /*
22 NSString *seachStr = @"12345.doc";
23 BOOL f = [seachStr hasPrefix:@"123"];//判断A字符串是否以B字符串为开头
24 BOOL f1 = [seachStr hasSuffix:@".doc"];//判断A字符串是否以B字符串结尾
25 NSRange range = [seachStr rangeOfString:@"234"];//搜索B字符串在A字符串中的范围
26 //库中的NSRange(包含了位置和长度的结构体)
27 // typedef struct _NSRange {
28 // NSUInteger location;
29 // NSUInteger length;
30 // } NSRange;
31 NSLog(@"%d,%d,%lu,%lu",f,f1,(range.location),(range.length));//位置 长度 (unsigned long)
32
33 if (range.location == NSNotFound)
34 {
35 NSLog(@"没找到");
36 }*/
37
38 /*
39 NSString *subResource = @"abcde";
40 NSString *subStr = [subResource substringFromIndex:3];//从位置1开始剪切字符串,包含1
41 NSLog(@"%@",subStr);
42
43 NSString *subStr2 = [subResource substringToIndex:3];//剪切到位置3,不包含3,留下3
44 NSLog(@"%@",subStr2);
45 */
46 /*
47 NSString *subResource = @"abcde";
48 NSRange range1 = NSMakeRange(1, 2);
49 // range1.location = 1;//位置
50 // range1.length = 2;//长度
51 //等价
52 //库中的NSMakeRange
53 // NS_INLINE NSRange NSMakeRange(NSUInteger loc, NSUInteger len) {
54 // NSRange r;
55 // r.location = loc;
56 // r.length = len;
57 // return r;
58 // }
59 NSString *subStr3 = [subResource substringWithRange:range1];//剪切给定范围的字符串
60 //compare方法:1.升序:前 < 后(-1),2.相等0 3.降序:前 > 后(1)
61 NSLog(@"%@",subStr3);*/
62
63 // NSLog(@"%d",(NSComparisonResult result = [@"ABC" compare:@"abc"]));
64 NSComparisonResult/*枚举类型*/ result = [@"abc" compare:@"abc" ] ;
65 NSLog(@"%ld",result);// NSOrderedAscending = -1L,存储类型L
66 //typedef NS_ENUM(NSInteger, NSComparisonResult) {NSOrderedAscending = -1L, NSOrderedSame, NSOrderedDescending};
67
68
69
70 }
71 return 0;
72 }
标签:
原文地址:http://www.cnblogs.com/liuguan/p/4907628.html