//
// 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]-; i>=; 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[]={};
char str2[]={};
scanf("%[^\n]\n%[^\n]",str1,str2);
//NSLog(@"%s\n%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=; 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 ;
}

OC3_字符串分割的更多相关文章

  1. SQL Server 游标运用:鼠标轨迹字符串分割

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 游标模板(Cursor Template) 鼠标轨迹字符串分割SQL脚本实现(SQL Code ...

  2. Oracle 超长字符串分割劈分

    Oracle 超长字符串分割劈分,具体能有多长没测过,反正很大.... 下面,,,,直奔主题了: CREATE OR REPLACE FUNCTION splitstr(p_string IN clo ...

  3. php学习零散笔记—字符串分割、fetch函数和单双引号。

    1 字符串分割——split()函数和preg_split()函数 split — 用正则表达式将字符串分割到数组中——貌似PHP5.3以上已不赞成使用 array split ( string $p ...

  4. 工作中用到的oracle字符串分割整理

    oracle部分: 定义类型(用于字符串分割): create or replace TYPE "STR_SPLIT" IS TABLE OF VARCHAR2 (4000); 字 ...

  5. Python 字符串分割的方法

    在平时工作的时候,发现对于字符串分割的方法用的比较多,下面对分割字符串方法进行总结一下:第一种:split()函数split()函数应该说是分割字符串使用最多的函数用法:str.split('分割符' ...

  6. 在C++中实现字符串分割--split

    字符串分割 在一些比较流行的语言中,字符串分割是一个比较重要的方法,不论是在python,java这样的系统级语言还是js这样的前端脚本都会在用到字符串的分割,然而在c++中却没有这样的方法用来调用. ...

  7. 随笔 JS 字符串 分割成字符串数组 并动态添加到指定ID的DOM 里

    JS /* * 字符串 分割成字符串数组 并动态添加到指定ID的DOM 里 * @id 要插入到DOM元素的ID * * 输入值为图片URL 字符串 * */ function addImages(i ...

  8. js 字符串分割成字符串数组 遍历数组插入指定DOM里 原生JS效果

    使用的TP3.2 JS字符串分割成字符串数组 var images='{$content.pictureurl} ' ;结构是这样 attachment/picture/uploadify/20141 ...

  9. oracle根据分隔符将字符串分割成数组函数

    --创建表类型 create or replace type mytype as table of number;--如果定义成varchar--CREATE OR REPLACE type myty ...

随机推荐

  1. android应用的界面编程----View与ViewGroup的概念

    1 UI OverView Android中所有的UI元素都是通过View与ViewGroup来构建的,View是指屏幕中一块可与用户进行交互的空白,类似于java界面编程中的JPanel.为了界面布 ...

  2. 如何让Iconfont作用到content伪类中

    沿用同行思密达的方法整理了一下;前提是先引入iconfont字体图标(引用线上iconfont查看上篇随笔):比如 其中&#是开头用以标明这是字符实体,x表示这是十六进制,而CSS的cont ...

  3. SVN遇到的几个错误问题解决办法

    1.svn更新被锁 清理之后陷入死循环问题 Attempted to lock an already-locked dir svn: Working copy 'E:\Workspaces\eclip ...

  4. <property name="current_session_context_class">thread</property> 属性

    <property name="current_session_context_class">thread</property>这个属性的作用:这样配置是本 ...

  5. 9 个让 JavaScript 调试更简单的 Console 命令

    一.显示信息的命令 <!DOCTYPE html> <html> <head> <title>常用console命令</title> < ...

  6. vertical-align:top在单词和中文的表现

    <ul> <li> <img src="../../saasdist_v2/images/staff-img.png" alt="" ...

  7. 给postfix设置黑名单

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  8. 【转】/etc/grub.conf文件详解

    转自:http://leejia.blog.51cto.com/4356849/788902 grub.conf是grub的主配置文件,通过这个配置文件,grub才能找到kernel,系统才能正常启动 ...

  9. C#WinForm应用程序实现自动填充网页上的用户名和密码并点击登录按钮【转载】

    使用WebBrowser控件,在documentComplete事件处理器里写 HtmlElement name = webBrowser1.Document.GetElementById(" ...

  10. 使用RecyclerView写树形结构的TreeRecyclerView

    简单介绍 android是不提供树形控件的,假设须要使用树形控件.我们应该怎么做呢? 先看效果 上图是一个明显的树形结构 实现原理 在逻辑上,它们是包括关系.数据结构上是多叉树,这是毋庸置疑的. 可是 ...