- oc字符串和c语言字符串之间的转换
- oc字符串检查大小写转换
- oc字符串特定的前缀和后缀检测
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSLog(@"Hello, World!");
char *s = "hello c";
NSString *str = @"Hello objective-c";
NSString *str1 = [NSString stringWithUTF8String: s];
NSLog(@"str1 = %@", str1);
NSLog(@"str1 = %s", [str UTF8String]);
NSString *str3 = @"IOS";
NSString *str4 = [[NSString alloc] init];
str4 = @"ios";
int a = 10;
int b = 20;
NSString *str5 = [NSString stringWithFormat:@"a=%d b=%d", a, b];
NSLog(@"str5 = %@", str5);
NSString *str6 = [str5 stringByAppendingString: str3];
NSLog(@"str6 = %@", str6);
NSString *str7 = @"ABCdeF";
NSString *str8 = [str7 lowercaseString];
NSLog(@"str8= %@", str8);
NSString *str9 = [str7 uppercaseString];
NSLog(@"str8= %@", str9);
NSString *str10 = @"www.imooc.com";
BOOL hasPrefix = [str10 hasPrefix:@"www."];
if(hasPrefix){
NSLog(@"有对应的前缀");
} else{
NSLog(@"没有对应的前缀");
}
BOOL hasSuffix = [str10 hasSuffix:@".com"];
if(hasSuffix){
NSLog(@"有对应的后缀");
} else{
NSLog(@"没有对应的后缀");
}
}
return 0;
}