1.把字符串写入到制定文件夹中
  NSString *myString = @"rongtianText  –Intexnet";
        NSError *error;
        NSString *path = [NSHomeDirectory() stringByAppendingPathCom ponent:@"tmp/rongtian.txt"];
        if (![myString writeToFile:path  atomically:YES  encoding:NSUTF8StringEncoding error:&error]) {
                NSLog(@"写入文件错误 %@",error);
                return;
        }

2.NSString范围
  NSRange r;
        r.location = 4;
        r.length = 5;
        NSString *strSub = [str substringWithRange:r];
        NSLog(@"范围   %@",strSub);
3.搜索
        NSRange searchRange  = [str rangeOfString:@"five"];
        if (searchRange.location != NSNotFound) {
                NSLog(@"搜索 location   %d     %d",searchRange.location,searchRange.length);
        }
4.替换
  NSString *replaced = [str stringByReplacingOccurre ncesOfString:@" " withString:@"+"];
        NSLog(@"替换的文件   %@",replaced);

#pragma mark -字符串的比较

void text() {

    NSString * str = @"RongTian";

    // 转成大写

    [str uppercaseString];

    // 转成小写

    [str lowercaseString];

    // 首字母大写,其余小写

    [@"ffEW" capitalizedString];

    

}



#pragma mark 比较2个字符串的大小

void compareString() {

    

    // NSOrderedAscending    -1

    // NSOrderedSame

    // NSOrderedDescending

    

   

  NSComparisonResult result = [@"bmn" compare:@"azz"];

    if (result == NSOrderedSame) {

        NSLog(@"左 == 右");

    }else if (result == NSOrderedDescending) {

        NSLog(@"左 > 右");

    }else if (result == NSOrderedAscending)

    {

        NSLog(@"左 <</span> 右");

    }

    

   

    NSComparisonResult caseInsenresult = [@"dffA" caseInsensitiveCompare:@"dffa"];

    if (caseInsenresult == NSOrderedSame) {

        NSLog(@"左 == 右");

    }else if (caseInsenresult == NSOrderedDescending) {

        NSLog(@"左 > 右");

    }else if (caseInsenresult == NSOrderedAscending)

    {

        NSLog(@"左 <</span> 右");

    }

}



#pragma mark 字符串的搜索

void searchString() {

       NSString *str = @"456789456";

    NSLog(@"是否456开头 %i", [str hasPrefix:@"456"]);

    NSLog(@"是否789结尾 %i",[str hasSuffix:@"789"]);

    

    NSRange range = [str rangeOfString:@"567"];

    if (range.location == NSNotFound) {

        NSLog(@"str中没有找到 567");

    }else {

        NSLog(@"搜索范围 %@",NSStringFromRange(range));

    }

    // 或者

//    if (range.length == 0 ) {

//        NSLog(@"str中没有找到 567");

//    }

   

    // 从尾开始搜索

    range = [str rangeOfString:@"456" options:NSBackwardsSearch] ;

    NSLog(@"从尾搜索的范围 %@",NSStringFromRange(range));

       

//    [str rangeOfString: