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;
    }
    

  • 相关阅读:
    代码规范问题
    HTML页面中显示HTML标签<xmp>
    controller.tabBarItem.title = @"11111"不显示
    xcode9报错 Safe Area Layout Guide before iOS9.0
    iBeacon
    protocol buffer
    关于沙漠君 | 一只特立独行的猪
    机器学习预测机动车摇号:神秘的第七位
    专注的价值
    Hawk 3.1 动态页面,ajax,瀑布流
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/2036195.html
Copyright © 2011-2022 走看看