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

  • 相关阅读:
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    基于分布式锁解决定时任务重复问题
    基于Redis的Setnx实现分布式锁
    基于数据库悲观锁的分布式锁
    使用锁解决电商中的超卖
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/2036195.html
Copyright © 2011-2022 走看看