//
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)