Oc3_ String Segmentation

Source: Internet
Author: User

////main.m//oc3_ String Segmentation////Created by zhangxueming on 15/6/11.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import<Foundation/Foundation.h>/*2. The symmetric string is passed in a string, combining the string into a new symmetric string returned for example: incoming: @ "I love you Mery" return: @ "I love you mery mery*///2, String split @ "I #am Prime # # #Optimus"//the string splitting function is split by the @ "#" string as a whole//3 There are two strings @ "I am a good girl Hello World"; @ "You were a bad boy"; fold the two string words together to form a new string @ "I am is a a good bad girl boy "intMainintargcConst Char*argv[]) {@autoreleasepool {#if0//splits a string in an incoming string as a whole//-(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#if0//split as a whole stringNsarray *array = [@"I #am Prime # # #Optimus"Componentsseparatedbystring:@" #"]; NSLog (@"array =%@", array); //to split with a character setNsarray *array2 = [@"I #am Prime # # #Optimus"Componentsseparatedbycharactersinset:[nscharacterset charactersetwithcharactersinstring:@" #"]]; NSLog (@"array2 =%@", array2);#endif        Charstr1[ -]={}; Charstr2[ -]={}; 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=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;}

Oc3_ String Segmentation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.