zoukankan      html  css  js  c++  java
  • NSString

    1. 折分字符串操作:

    #import <Foundation/Foundation.h>
    
    int main (int argc, const char * argv[])
    {
    
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
        //将一个句子分解为单独的单词 
        NSString *string1 = @"my name is bill";
        NSArray *words = [string1 componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
        NSLog(@"Word array: %@", words);
        
        //把一个NSString追加到另一个NSString
        NSString *str1 = @"第一个字符串 ";
        NSString *str2 = @"第二个字符串。";
        NSString *result = [str1 stringByAppendingFormat:str2];
        NSLog(@"result: %@", result);
    
        [pool drain];
        return 0;
    }
    

    2. C字符串和NSString之间的转换

    #import <Foundation/Foundation.h>
    
    int main (int argc, const char * argv[])
    {
    
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
        //C字符串和NSString之间的转换
        char* cString = "Hello bill.";
        NSString *nsString = [NSString stringWithUTF8String:cString];
        NSLog(@"%@\r\n",nsString);
        
        char* cString2 = [nsString UTF8String];
        printf(cString2);
        printf("\r\n");
    
        [pool drain];
        return 0;
    }
    

    3.可变字符串

    #import <Foundation/Foundation.h>
    
    int main (int argc, const char * argv[])
    {
    
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
        NSMutableString *mutableString = [NSMutableString stringWithString:@"可变字符串:"];
        
        [mutableString insertString:@"NSMutableString" atIndex:[mutableString length]];
        
        NSLog(@"%@", mutableString);
    
        [pool drain];
        return 0;
    }
    

  • 相关阅读:
    django的用户认证模块(auth)
    算法
    图书管理系统
    mac系统中pycharm激活
    mac常见问题
    mysql安装
    restful规范及DRF基础
    MySQL存储引擎
    [python] with statement
    MySQL索引及执行计划
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/2036195.html
Copyright © 2011-2022 走看看