Small white Learning Development (IOS) OC_ string reorganization (2015-08-13)

Source: Internet
Author: User

//

Main.m

// string reorganization

//

Created by admin on 15/8/13.

Copyright (c) years admin. All rights reserved.

//


#import <Foundation/Foundation.h>


int Main (int argc,const Char * argv[]) {

@autoreleasepool {

//1. Multiple data stitching into a single string

int year = ;

int month = 8;

int day = ten;

nsstring *date = [nsstringstringwithformat:@ "%d years %d months %d days ", Year,month,day];

NSLog (@ " date :%@", date);

nsstring *address = @ " somewhere in the earth ";

nsstring *dateandaddress = [nsstringstringwithformat:@ " time :%@ location :%@ ", date,address];

NSLog (@ "%@", dateandaddress);

//2. Appends a new character to the end of a string

nsstring *str1 = @ "www.";

nsstring *str2 = [str1 stringbyappendingstring:@ "Baidu"];

nsstring *str3 = [str2 stringbyappendingstring:@ ". com"];

NSLog (@ "str1:%@ str2:%@ str3:%@", str1, str2, STR3);

//3. Append a string to a custom scope

nsstring *STR4 = @ "www..com";

nsrange range = {4,5};

nsstring *STR5 = [Str3stringbyreplacingcharactersinrange: Range withstring: @ "Baidu"];

NSLog (@ "STR4:%@ str5:%@", STR4, STR5);

//4. Replace the original character with the new string

nsstring *STR6 = @ "www.baidu.com";

( where to customize the replacement )

nsstring *str7 = [STR6stringbyreplacingcharactersinrange: Range withstring: @ "Google");

NSLog (@ "STR6:%@ str7:%@", STR6, STR7);

( replace W all in the string with t)

nsstring *str8 = [STR6stringbyreplacingoccurrencesofstring:@ "W" /c5>withstring:@ "T"];

NSLog (@ "str8:%@", str8);

//5. Remove some specific characters from the string: replace the t above with empty

nsstring *str9 = [STR6stringbyreplacingoccurrencesofstring:@ ".] withstring:@ ""];

NSLog (@ "STR9:%@", STR9);

6. remove spaces from a string

nsstring *str10 =@ "www. Bai du.co m ";

nsstring *str11 = [Str10stringbyreplacingoccurrencesofstring:@ "" withstring:@ ""];

NSLog (@ "Str10:%@ str11:%@", Str10, Str11);

}

return 0;

}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Small white Learning Development (IOS) OC_ string reorganization (2015-08-13)

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.