main:
-
- #import <Foundation/Foundation.h>
- #import "StringText.h"
-
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
-
- NSLog(@"Hello, World!");
- StringText *stringText = [[StringText alloc] init];
- [stringText test];
- }
- return 0;
- }
h:
-
- #import <Cocoa/Cocoa.h>
-
- @interface StringText : NSObject
-
- -(void)test;
- -(void) createString;
- -(void) appendString;
- -(void) seperaterString;
-
- @end
-
- #import "StringText.h"
-
- @implementation StringText
-
- - (void)test {
- [self createString];
- [self appendString];
- }
- -(void) createString{
- NSString *string1 = [[NSString alloc] init];
- NSLog(@"string1 %@",string1);
- NSLog(@"string1 %p",string1);
-
- string1 = @"";
- NSLog(@"string1 %@",string1);
- NSLog(@"string1 %p",string1);
-
- NSString *string2 = @"Hello World";
- NSLog(@"string2 %@",string2);
- NSLog(@"string2 %p",string2);
-
-
- NSString *string3 = @"Hello World";
- NSLog(@"string3 %@",string3);
- NSLog(@"string3 %p",string3);
-
-
- const char *cString = "c Language String";
- NSString *objectCString = [NSString stringWithCString:cString encoding:NSUTF8StringEncoding];
- NSLog(@"c语言的字符串输出:%@",objectCString);
-
-
- NSString *format = @"%@年%@月%@日";
- NSString *fromatedNSString = [NSString stringWithFormat:format,@"1949",@"10",@"1"];
- NSLog(@"格式化输出的结果:%@",fromatedNSString);
-
- }
-
- -(void) appendString{
-
- NSString *string1 = @"www.";
- NSString *string2 = @"baidu.com";
-
- NSString *string3 = [NSString stringWithFormat:@"%@%@",string1,string2];
- NSLog(@"字符串的拼接%@",string3);
-
-
- NSString *string4 = [string3 stringByAppendingFormat:@"%@%@",@"haha",@"hehe"];
- NSLog(@"字符串的拼接%@",string4);
-
-
- NSString *string5 = [string4 stringByAppendingString:@" 我是kodulf,我一个梦想,中国足球走向世界"];
- NSLog(@"字符串的拼接%@",string5);
-
- }
-
- -(void) seperaterString{
- NSString *string = @"字符串的拼接www.baidu.comhahahehe 我是kodulf,我一个梦想,中国足球走向世界";
- NSArray<NSString *> *components = [string componentsSeparatedByString:@"."];
- NSLog()
- }
- @end
分隔还可以参考:
|
请发表评论