OC基础之 ------------- Foundation 框架 / 字符串 /数组 / 结构体 / 时间/文件

//推荐博客篇

http://blog.csdn.net/chengyingzhilian/article/details/7894195          讲解的特别细

使用CGPoint这些方法时,需要引入 <CoreGraphics/CGBase.h> <CoreFoundation/CFDictionary.h>框架

1.CGPoint

//定义

struct CGPoint {
  CGFloat x;
  CGFloat y;
};

typedef struct CGPoint ;

//方法

//1.创建一个CGPoint ,坐标x.y

CGPoint point =   CGPointMake(CGFloat x, CGFloat y);

//2. 比较两个点是否相同

bool CGPointEqualToPoint(CGPoint point1, CGPoint point2)

//3.判断右边这个点,在不在rect这个巨型框中

 bool CGRectContainsPoint(CGRect rect, CGPoint point)

//4.//把点转换为不可变字典

CFDictionaryRefCGPointCreateDictionaryRepresentation(CGPoint point)

//5。看这个点在不在这个字典中

bool CGPointMakeWithDictionaryRepresentation(CFDictionaryRef dict,  CGPoint *point)

2.CGsize

//定义

/* Sizes. */

struct CGSize {
  CGFloat width;
  CGFloat height;
};
typedef struct CGSize CGSize;

//   原点  0 。0 ,宽度和高度都是0

const CGSize CGSizeZero

//方法
//1.创建一个CGSize ,宽度 witch  ,高度  height

CGSizeMake(CGFloat width, CGFloat height);

//2. 比较两个矩形框 大小是否一样    返回值bool

bool CGSizeEqualToSize(CGSize size1, CGSize size2)

//4.// 矩形宽高转换为不可变字典

CFDictionaryRef CGSizeCreateDictionaryRepresentation(CGSize size)

//5 判断矩形  在不在字典中

bool CGSizeMakeWithDictionaryRepresentation(CFDictionaryRef dict, CGSize *size)


2.CGRect

//定义

struct CGRect {
  CGPoint origin;
  CGSize size;
};
typedef struct CGRect CGRect;

const CGRect CGRectZero    自适应大小

//方法

//1.创建一个CGRect ,坐标x.y  宽高 widch   height

CGRectMake(CGFloat x, CGFloat y, CGFloat width,CGFloat height);

//2. 比较两个CGRect是不是一样的

bool CGSizeEqualToSize(CGSize size1, CGSize size2)

//3.判断右边这个点,在不在rect这个巨型框中


//4.//把CGRect转换为不可变字典

 CFDictionaryRef CGRectCreateDictionaryRepresentation(CGRect)

//5。看这个CGRect在不在这个字典中,返回类型是bool

bool CGRectMakeWithDictionaryRepresentation(CFDictionaryRef dict,  CGRect *rect)


字符串  NSString

- (BOOL)containsString:(NSString *)aString   //字符串是否包含这个字符


 /**  1.获取字符串 */
        NSString *str = @"www.itcast.com";
        NSUInteger len = [str length];
        NSLog(@"%ld",len);
        
        /**  2.根据索引获得单个字符串 */
        NSString *str1 = @"www.itcast.com";
        //注意,索引如果超出字符串长度 ,报一异常错误Range or index out of bounds
        unichar c = [str1 characterAtIndex:1];
        NSLog(@"%c",c);
        
        
        /**  3.根据索引获得一个子串 */
        NSString *str2 = @"www.itcast.com";
        //substringFromIndex 从索引位置开始(包括索引位置)截取到字符串末尾
        NSString *tep = [str2 substringFromIndex:3]; //substringToIndex 截取字符串到指定索引位置开始(不包括索引位置)
        NSString *tep2 = [str2 substringToIndex:3];
        //**注意以上两个方法获取的是一个全新的字符串 不对原来的字符串做任何改变
        
        
        
        /**  4.截取字符串的某一段 */
        //** location(起始索引的位置)  length(要截取的长度)
        NSRange rage = {4,6};
        NSString *str3 = @"www.itcast.com";
        NSString *ragestr = [str3 substringWithRange:rage];
        
        
        
        /**  5.获取一个字符串在 另一个字符串的索引位置 */
        //可以用来判断一个字符串中 是否包含另一个字符串
        NSString *str4 = @"www.itcast.com";
        NSString *str5 = @" ";
        NSRange rag = [str4 rangeOfString:str5];
        NSLog(@"%lu------%lu",(unsigned long)rag.location,(unsigned long)rag.length);
        //NSNotFound 该字符串没有对应字符  ** 注意 这个必须判断
        if (rag.location == NSNotFound) {
            NSLog(@"str5 不在 str4 中");
        }else {
            NSLog(@"%@",NSStringFromRange(rag));
        }
        
         /**  6.获取一个字符串在 另一个字符串的索引位置 */
        //<#(NSStringCompareOptions)#> --NSCaseInsensitiveSearch 一般填这个
        NSString *str6 = @"www.itcast.com";
        NSString *str7 = @"itcast";
        NSRange range = [str6 rangeOfString:str7 options:NSCaseInsensitiveSearch];

 //1.判断字符串时否为空
        NSString *str = @"";
        if (str == nil || str.length == 0) {
            NSLog(@"字符串为空");
        }
        
        //2.判断一个字符串时否包含空
        NSString *str1 = @"";
        NSString *str2 = @"www.itcast.com";
        NSRange rage = [str2 rangeOfString:str1];
        if (rage.location == NSNotFound) {
            NSLog(@"不包含 str 字符串");
        }
        
        //3.判断字符串时否已指定内容开头 hasPrefix
        NSString *str3 = @"www.itcast.com";
        BOOL isPrefix = [str3 hasPrefix:@"www"];
        NSLog(@"%@",isPrefix ? @"YES" : @"NO");
        
        //4.判断字符串时否已指定内容结尾 hasSuffix
        //**常用在 判断文件格式上
        //** txt,avi,rmvb,mkv,doc,mp3,mp4,pdf
        NSString *str4 = @"www.itcast.com";
        BOOL isSuffix = [str4 hasSuffix:@"com"];
        NSLog(@"%@",isSuffix ? @"YES" : @"NO");
        
        //5.判断字符串是否相等
        NSString *pstr = @"www.itcast.com";
        NSString *pstr1 = @"www.itcast.com";
        NSString *pstr2 = pstr;
        //这个时候 pstr,pstr1,pstr2 地址都是一样的
        if (pstr == pstr1) {
            //这里判断的是 地址 因为有字符串池
            NSLog(@"str--%p,str1--%p",str,str1);
        }
        
        if(pstr == pstr2) {
            //这里判断的是地址 地址是不一样的  是直接指向str指向的内存地址
            NSLog(@"str--%p,str2--%p",str,str2);
        }
        //使用 == 号 判断的是字符串地址是否相等
        //如果地址相同 两个字符串相等
        NSString *pstr3 = [NSString stringWithFormat:@"www.itcast.com"];
        if(pstr3 == pstr2) {
            //这里判断
            NSLog(@"str2--%p,str3--%p",str2,str3);
        }
        
        //判断两个字符串是否相等 isEqualToString 取出每个字符串进行比较
        BOOL isEqua = [str3 isEqualToString:str2];
        
        
        //6. compare 是 isEqualToString 升级版  给三个答案供你选
             //Ascii值比大小
             //挨个字符比较
        NSString *tmp = @"abc";
        NSString *tmp1 = @"Abc";
        NSComparisonResult result = [tmp compare:tmp1];
        switch (result) {
            case NSOrderedAscending:
                NSLog(@"0");
                break;
            case NSOrderedSame:
                NSLog(@"字符串相等 1");
                break;
            case NSOrderedDescending:
                NSLog(@"2");
                break;
                
            default:
                break;
        }


 //7.将字符串写入某个文件中
        NSString *name = @"林芳";
        NSURL *url = [NSURL fileURLWithPath:@"/Users/longshao/Desktop/01-课堂笔记.m"];
        /**
         *  将name 写进文件中
         *
         *  @param NSURL 资源路径
         * @atomically 如果是yes  失败是不会再次写的
         *
         *  @NSStringEncoding 转码  中文转码
         */
        [name writeToURL:url atomically:YES encoding:(NSUTF8StringEncoding) error:nil];
       







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值