【Foundation-62-1】#import <Foundation/NSRange.h>范围
来源:互联网 发布:ray面膜 知乎 编辑:程序博客网 时间:2024/06/09 07:42
// NSRange 的结构体
typedef struct _NSRange {
NSUInteger location;
NSUInteger length;
} NSRange;
NSRange theRange = NSMakeRange(2, 4); NSUInteger loc = theRange.location; // 起始位置 NSUInteger len = theRange.length; // 长度
// NSRange 的指针 啥用子类?没用过,求告知
typedefNSRange *NSRangePointer;
????
// 创建 NSRange
NS_INLINENSRange NSMakeRange(NSUInteger loc,NSUInteger len) {
NSRange r;
r.location = loc;
r.length = len;
return r;
}
NSRange theRange = NSMakeRange(2, 4);
// 最大值
NS_INLINENSUInteger NSMaxRange(NSRange range) {
return (range.location + range.length);
}
NSRange theRange = NSMakeRange(2, 4); NSUInteger six = NSMaxRange(theRange);<span style="white-space:pre"></span>
// 判断位置是否在 范围内
NS_INLINEBOOL NSLocationInRange(NSUInteger loc,NSRange range) {
return (!(loc < range.location) && (loc - range.location) < range.length) ?YES : NO;
}
if (NSLocationInRange(3, NSMakeRange(1, 4))) { NSLog(@"yes"); }
// 判断2个范围是否完全一致
NS_INLINEBOOL NSEqualRanges(NSRange range1,NSRange range2) {
return (range1.location == range2.location && range1.length == range2.length);
}
if (NSEqualRanges(NSMakeRange(1, 2), NSMakeRange(2, 3))) { NSLog(@"yes"); }
FOUNDATION_EXPORTNSRange NSUnionRange(NSRange range1,NSRange range2);// 并集
FOUNDATION_EXPORTNSRange NSIntersectionRange(NSRange range1,NSRange range2);// 交集
FOUNDATION_EXPORTNSString *NSStringFromRange(NSRange range);// 范围转字符串
FOUNDATION_EXPORTNSRange NSRangeFromString(NSString *aString);// 字符串转范围
NSRange range1 = NSMakeRange(1, 5);<span style="white-space:pre"></span>12345 NSRange range2 = NSMakeRange(3, 5);<span style="white-space:pre"></span>34567 NSRange unionRange = NSUnionRange(range1, range2);<span style="white-space:pre"></span>1234567 NSRange intersectionRange = NSIntersectionRange(range1, range2);<span style="white-space:pre"></span>345 NSString *rangeStr = NSStringFromRange(range1);<span style="white-space:pre"></span>{1,5} NSLog(@"%@",rangeStr); NSRange strRange = NSRangeFromString(@"{1,4}");
@interface NSValue (NSValueRangeExtensions)
+ (NSValue *)valueWithRange:(NSRange)range;// 通过范围创建NSValue
@property (readonly)NSRange rangeValue;
@end
- 【Foundation-62-1】#import <Foundation/NSRange.h>范围
- 【Foundation-10-1】#import <Foundation/NSArray.h>
- Foundation--NSRange
- 【Foundation-36-1】#import <Foundation/NSIndexPath.h>树结构
- 【Foundation-37-1】#import <Foundation/NSIndexSet.h>不可索引集合
- 【Foundation-86-1】#import <Foundation/NSValue.h>基础创建
- 【Foundation-26-1】#import <Foundation/NSDictionary.h>字典,旧
- 【Foundation-86-2】#import <Foundation/NSValue.h>
- 【Foundation-10-2】#import <Foundation/NSArray.h>
- OC--Foundation-NSRange
- Foundation中的NSRange
- 【Foundation-37-2】#import <Foundation/NSIndexSet.h>可变索引集合
- 【Foundation-86-3】#import <Foundation/NSValue.h> 初始化
- 【Foundation-10-3】#import <Foundation/NSArray.h>遍历
- 【Foundation-10-3】#import <Foundation/NSArray.h>排序
- 【Foundation-10-4】#import <Foundation/NSArray.h>可变数组,一般
- 【Foundation-10-5】#import <Foundation/NSArray.h>可变数组,操作
- 【Foundation-26-2】#import <Foundation/NSDictionary.h>字典创建
- POJ 2182&& POJ 2828:Lost Cows 从后往前 线段树
- 数据结构初语~
- <Android知识点整理>0.序
- java 实现动态代理
- ActionBar
- 【Foundation-62-1】#import <Foundation/NSRange.h>范围
- 数据结构学习规划~
- 【特种兵PPT教程】如何实现PPT播放时内部页间的跳转?
- 【设计模式】(一)单例模式
- awk笔记
- ERROR - 文件名:D:\31X.bmp, 错误码: -1304, 错误原因: person info is null
- iOS开发:UISwitch 与 UIActivityIndicatorView
- 二分查找的递归实现和迭代实现
- Codeforces 549D Haar Features (模拟)