zoukankan      html  css  js  c++  java
  • OC3_字符串分割

    //
    //  main.m
    //  OC3_字符串分割
    //
    //  Created by zhangxueming on 15/6/11.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    /*2.对称字符串
     传入一个字符串,将这个字符串组合成一个新的对称字符串返回
     例如:
     传入:@"I love you Mery"
     返回:@"I love you Mery Mery you love I"
     */
    
    //2, 字符串分割 @“I #am Prime  # # #Optimus”
    //字符串分割函数  按照 @" #"字符串整体分割
    
    
    //3有两个字符串@"I am a good girl hello world";@"You are a bad boy"; 将这两个字符串单词,交叠,形成新的字符串 @"I You am are a a good bad girl boy"
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
    #if 0
            //以传入的字符串整体分割字符串
            //- (NSArray *)componentsSeparatedByString:(NSString *)separator;
            NSArray *array = [@"I love you Mery" componentsSeparatedByString:@" "];
    //        NSMutableArray *mulArray = [NSMutableArray arrayWithArray:array];
    //        [mulArray removeObject:@""];
    //        NSLog(@"mulArray = %@", mulArray);
            NSArray *dstArray = [NSArray arrayWithArray:array];
            for (NSInteger i=[array count]-1; i>=0; i--) {
                dstArray = [dstArray arrayByAddingObject:[array objectAtIndex:i]];
            }
            NSString *dstString =[dstArray componentsJoinedByString:@" "];
            NSLog(@"dstString = %@", dstString);
    #endif
    #if 0
            //以字符串整体进行分割
            NSArray *array = [@"I #am Prime  # # #Optimus" componentsSeparatedByString:@" #"];
            NSLog(@"array = %@", array);
            //以字符集进行分割
            NSArray *array2 = [@"I #am Prime  # # #Optimus" componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" #"]];
            NSLog(@"array2 = %@", array2);
    #endif
            char str1[100]={};
            char str2[100]={};
            scanf("%[^
    ]
    %[^
    ]",str1,str2);
            //NSLog(@"%s
    %s", str1, str2);
            NSString *string1 = [NSString stringWithUTF8String:str1];
            NSString *string2 = [NSString stringWithUTF8String:str2];
            NSArray *array1 = [string1 componentsSeparatedByString:@" "];
            NSArray *array2 = [string2 componentsSeparatedByString:@" "];
            NSUInteger len1 = [array1 count];
            NSUInteger len2 = [array2 count];
            
            NSArray *dstArray = [NSArray array];
            NSUInteger len = len1>len2?len2:len1;
            for (NSInteger i=0; i<len; i++) {
                dstArray = [dstArray arrayByAddingObject:[array1 objectAtIndex:i]];
                dstArray = [dstArray arrayByAddingObject:[array2 objectAtIndex:i]];
            }
            
            NSArray *subArray =len1>len2?[array1 subarrayWithRange:NSMakeRange(len, len1-len)]:[array2 subarrayWithRange:NSMakeRange(len, len2-len)];
            dstArray = [dstArray arrayByAddingObjectsFromArray:subArray];
            NSString *dstString = [dstArray componentsJoinedByString:@" "];
            NSLog(@"dstString = %@", dstString);
        }
        return 0;
    }
  • 相关阅读:
    suse12安装详解
    Centos7上部署openstack mitaka配置详解(将疑难点都进行划分)
    菜鸟帮你跳过openstack配置过程中的坑[文末新添加福利]
    openstack中dashboard页面RuntimeError: Unable to create a new session key. It is likely that the cache is unavailable.
    Multiple network matches found for name 'selfservice', use an ID to be more specific.报错
    查看 SELinux状态及关闭SELinux
    SELinux深入理解
    IP地址、子网掩码、网络号、主机号、网络地址、主机地址
    Oracle job procedure 存储过程定时任务
    POI文件导出至EXCEL,并弹出下载框
  • 原文地址:https://www.cnblogs.com/0515offer/p/4569778.html
Copyright © 2011-2022 走看看