@property (readonly) NSUInteger length; //长度
/*
NSString *string = [[NSString alloc] initWithFormat:@"%@", @"xxpngxx.png"];
NSLog(@"%lu", [string length]);
*/
- (NSString *)substringFromIndex:(NSUInteger)from; //取子串
/*
NSString *string = [[NSString alloc] initWithFormat:@"%@", @"xxpngxx.png"];
NSString *s1 = [string substringFromIndex:3];
NSLog(@"s1 = %@", s1);
*/
- (NSString *)substringToIndex:(NSUInteger)to; //从头取到指定位置
/*
NSString *string = [[NSString alloc] initWithFormat:@"%@", @"xxpngxx.png"];
s1 = [string substringToIndex:3];
NSLog(@"s1 = %@", s1);
*/
- (NSString *)substringWithRange:(NSRange)range; //从制定的位置到后去指定定的长度
/*
s1 = [string substringWithRange:lomakeRange(5, 4)];
NSLog(@"s1 = %@", s1);
NSString *s2 = [[NSString alloc ] initWithFormat:@"老李"];
NSString *s3 = [[NSString alloc] initWithFormat:@"老张"];
NSLog(@"%ld", [s3 compare:s2]) ;
*/
- (NSComparisonResult)compare:(NSString *)string; //字符串的比较
/*
NSLog(@"%ld", [@"a" compare:@"A"]);
*/
- (NSComparisonResult)caseInsensitiveCompare:(NSString *)string; //不区分大小写的字符串比较
/*
NSLog(@"%ld", [@"a"caseInsensitiveCompare:@"A"]);
*/
- (BOOL)isEqualToString:(NSString *)aString; //字符串内容相等
/*
NSString *s4 = @"老王";
NSString *s5 = [[NSString alloc] initWithFormat: @"老王"];
if ([s4 isEqualToString:s5] == YES) {
NSLog(@"equal");
} else {
NSLog(@"not equal");
}
*/
- (BOOL)hasPrefix:(NSString *)aString; //前缀一样
/*
NSString *s6 = [[NSString alloc] initWithFormat:@"abcde"];
if ([s6 hasPrefix:@"de"]) {
NSLog(@"yes");
} else {
NSLog(@"No");
}
*/
- (BOOL)hasSuffix:(NSString *)aString; //后缀一样
/*
NSString *s6 = [[NSString alloc] initWithFormat:@"abcde"];
if ([s6 hasSuffix:@"de"]) {
NSLog(@"yes");
} else {
NSLog(@"No");
}
*/
- (BOOL)containsString:(NSString *)aString NS_AVAILABLE(10_10, 8_0);//包含
/*
if ([@"老李" containsString:@"李"]) {
NSLog(@"yes");
} else{
NSLog(@"No");
}
*/
- (NSRange)rangeOfString:(NSString *)aString; //包含信息
/*
NSString *string1 = [[NSString alloc] initWithFormat:@"老王是个好邻居"];
NSString *string2 = @"邻居";
NSRange s = NSMakeRange(0, 0);
s = [string1 rangeOfString:string2];
NSLog(@"location = %lu , length = %lu", s.location, s.length);
*/
- (NSString *)stringByAppendingString:(NSString *)aString; //拼接字符串
/*
NSString *string = [[NSString alloc] initWithFormat:@"%@", @"xxpngxx.png"];
NSLog(@"%lu", [string length]);
NSLog(@"s....%p", string);
if ([string hasSuffix:@"png"]) {
string = [string stringByReplacingOccurrencesOfString:@".png" withString:@".jpg"];
} else {
string = [string stringByAppendingString:@"jpg"];
}
NSLog(@"%@", string);
*/
- (NSString *)stringByAppendingFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2); //通过格式串进行拼接
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement NS_AVAILABLE(10_5, 2_0); //字符串替换
/*
NSString *string = [[NSString alloc] initWithFormat:@"%@", @"xxpngxx.png"];
NSLog(@"%lu", [string length]);
NSLog(@"s....%p", string);
if ([string hasSuffix:@"png"]) {
string = [string stringByReplacingOccurrencesOfString:@".png" withString:@".jpg"];
} else {
string = [string stringByAppendingString:@"jpg"];
}
NSLog(@"%@", string);
*/
@property (readonly) double doubleValue; //字符串转换成double型
@property (readonly) float floatValue; //字符串转换成float型
@property (readonly) int intValue; //字符串转换成int型
/*
NSString *string3 = [[NSString alloc] initWithFormat:@"%d", 123];
NSLog(@"%@", string3);
NSString *string = [[NSString alloc] initWithFormat:@"%@%d", string3, 456];
NSLog(@"%@", string);
int a = string.intValue;
NSLog(@"a = %d", a);
*/
@property (readonly) NSInteger integerValue NS_AVAILABLE(10_5, 2_0);
@property (readonly) long long longLongValue NS_AVAILABLE(10_5, 2_0);
@property (readonly) BOOL boolValue NS_AVAILABLE(10_5, 2_0);
//可变字符串
- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)aString; //在指定范围内进行替换
/*
NSMutableString *string1 = [[NSMutableString alloc] initWithFormat:@"%@", @"老王是个好邻居"];
NSRange r = [string1 rangeOfString:@"是"];
[string1 replaceCharactersInRange:r withString:@"真是"];
NSLog(@"%@", string1);
*/
- (void)insertString:(NSString *)aString atIndex:(NSUInteger)loc; //插入
/*
NSRange r1 = [string1 rangeOfString:@"邻居"];
[string1 insertString:@"色" atIndex:r1.location];
NSLog(@"%@", string1);
*/
- (void)appendString:(NSString *)aString; //拼接
/*
[string1 appendString:@", 难道不是么"];
NSLog(@"%@", string1);
*/
- (void)deleteCharactersInRange:(NSRange)range; //删除
/*
NSRange r2 = [string1 rangeOfString:@"色"];
[string1 deleteCharactersInRange:r2];
NSLog(@"%@", string1);
*/
- (NSMutableString *)initWithCapacity:(NSUInteger)capacity; //可变字符串初始化
/*
NSMutableString *string = [[NSMutableString alloc]initWithCapacity:10];
[string appendString:@"aasdad"];
NSLog(@"%@", string);
*/
//不可变数组
@property (readonly) NSUInteger count; //数组对象个数
/*
NSLog( @"count = %lu", [array count]);
*/
- (id)objectAtIndex:(NSUInteger)index; //数组对象的下标,用作数组的遍历
/*
NSArray *array = [[NSArray alloc] initWithObjects:@"aaa", @"bbb", @"ccc", nil];
for (int i = 0; i < [array count]; i++) {
NSLog(@"%@", [array objectAtIndex:i]);
// NSLog(@"%@", array[i]);
}
*/
- (NSArray *)arrayByAddingObject:(id)anObject; //数组拼接
/*
NSArray *array = [[NSArray alloc] initWithObjects:@"aaa", @"bbb", @"ccc", nil];
array = [array arrayByAddingObject:@"ddd"];
for (int i = 0; i < [array count]; i++) {
NSLog(@"%@", [array objectAtIndex:i]);
// NSLog(@"%@", array[i]);
}
*/
- (NSArray *)arrayByAddingObjectsFromArray:(NSArray *)otherArray; //从数组的最后拼接另一个数组
/*
NSArray *array = [[NSArray alloc] initWithObjects:@"aaa", @"bbb", @"ccc", nil];
NSArray *array1 = [[NSArray alloc] initWithObjects:@"eee", nil];
array = [array arrayByAddingObjectsFromArray:array1];
for (int i = 0; i < [array count]; i++) {
NSLog(@"%@", [array objectAtIndex:i]);
// NSLog(@"%@", array[i]);
}
*/
- (instancetype)initWithObjects:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION; //数组初始化
/*
NSArray *array = [[NSArray alloc] initWithObjects:@"aaa", @"bbb", @"ccc", nil];
*/
- (NSArray *)sortedArrayUsingFunction:(NSInteger (*)(id, id, void *))comparator context:(void *)context; //排序
- (BOOL)isEqualToArray:(NSArray *)otherArray; //两个数组内容进行比较
@property (nonatomic, readonly) id firstObject NS_AVAILABLE(10_6, 4_0); //读取数组的第一个对象
@property (nonatomic, readonly) id lastObject; //读取数组的最后一个对象
//可变数组
- (void)addObject:(id)anObject; // 在数组的最后进行添加对象
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index; // 在数组的指定位置进行对象添加
- (void)removeLastObject; //删除数组的最后对象
- (void)removeObjectAtIndex:(NSUInteger)index; //删除数组的指定位置的对象
- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject; //在数组的指定位置进行替换