// 首字母大写
NSString *string = @"liupengfei";
NSLog(@"\n function: %s \n string: %@",__FUNCTION__,[string capitalizedString]);
// 分割字符串
NSString *string1 = @"I am iOS Engineer";
NSArray *array = [string1 componentsSeparatedByString:@"iOS"];
NSLog(@"\n function: %s \n array: %@",__FUNCTION__,array);
NSString *str1 = [array objectAtIndex:0];
NSString *str2 = [array objectAtIndex:1];
NSLog(@"\n function: %s \n str1: %@ \n str2: %@", __FUNCTION__,str1, str2);
// 追加字符串
NSMutableString *muStr = [[NSMutableString alloc] initWithString:@"I Love "];
[muStr appendString:@"iOS"];
NSLog(@"\n function: %s \n muStr: %@", __FUNCTION__,muStr);
// 插入字符串
NSMutableString *muString = [[NSMutableString alloc] initWithString:@"I iOS"];
[muString insertString:@"Love" atIndex:2];
NSLog(@"\n function: %s \n muString: %@", __FUNCTION__,muString);
// 删除字符串
NSMutableString *muString1 = [[NSMutableString alloc] initWithString:@"I Love iOS"];
[muString1 deleteCharactersInRange:NSMakeRange(2, 4)];
NSLog(@"\n function: %s \n muString1: %@", __FUNCTION__, muString1);
// 判断是否包含前后缀
NSMutableString *muString2 = [[NSMutableString alloc] initWithString:@"I Love iOS"];
BOOL isHasI = [muString2 hasPrefix:@"I"];
BOOL isHasA = [muString2 hasPrefix:@"A"];
NSLog(@"\n function: %s \n isHasI: %d \n isHasA: %d", __FUNCTION__,isHasI,isHasA);
// 替换字符串
NSMutableString *muString3 = [[NSMutableString alloc] initWithString:@"I Love iOS"];
NSString *replaceString = [muString3 stringByReplacingOccurrencesOfString:@"Love" withString:@"Hit"];
NSLog(@"\n function: %s \n replaceString: %@", __FUNCTION__,replaceString);
// 去除字符串首尾的空格和换行符
NSString *string = @" I Love iOS ";
NSString *text = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"\n function: %s \n text:%@", __FUNCTION__,text);