OC----String array iOS learning-----crushing Knowledge points Summary

Source: Internet
Author: User

NSString *urlstring = [NSString stringwithformat:@ "http://www.apple.com"];

Get string length
NSLog (@ "Length:%lu", [urlstring length]);

Find substring
NSLog (@ "%@", [urlstring substringfromindex:4]);
NSLog (@ "urlstring =%@", urlstring);
Stitching strings
NSLog (@ "======%@", [urlstring stringbyappendingstring:@ "1234"]);

Replace string
NSLog (@ "--===-===%@", [urlstring stringbyreplacingoccurrencesofstring:@ "www" withstring:@ "M"]);

String equality
NSLog (@ "-----%d", [urlstring isequaltostring:@ "http://www.apple.com"]);

string comparison
NSLog (@ "=====%ld", [urlstring compare:@ "H"]);

#pragma mark-nsmutablestring: variable string
Stitching strings
[Mutablestring appendstring:@ "2234"]; operate on the basis of the original string
NSLog (@ "---%@", mutablestring);

Insert
[Mutablestring insertstring:@ "ABCD" atindex:0];
NSLog (@ "--==-%@", mutablestring);

Delete
[Mutablestring Deletecharactersinrange:range];
NSLog (@ "--=+====-%@", mutablestring);

Replace
[mutablestring replacecharactersinrange:range withstring:@ "www"];
NSLog (@ "--=====-%@", mutablestring);

For NSString, the method of operation is generally beginning with Stringby, the method has a return value, to get a new string, for nsmutablestring, the general operation is its own

Array gets the number of elements in the array, the elements behind the Nill are not counted.

Gets the element corresponding to the position in the array
NSLog (@ "====%@", [Arry objectatindex:10]);
Array out of bounds

NSLog (@ "---%@", [Arry Lastobject]);
NSLog (@ "====%@", [Arry Firstobject]);

#pragma mark-nsmutablearry
instance method to create an object
Nsmutablearray *arry1 = [[Nsmutablearray alloc] initwithobjects:@ "Journey to the Monkey", @ "Red mansions", @ "kingdoms", @ "Outlaws of the Marsh", nil];
Create objects with a sharp tool
Nsmutablearray *arry2 = [Nsmutablearray arraywithobjects:@ "Zhao Yun", @ "Ma Chao", Nil];
Nsmutablearray *arry3 = [Nsmutablearray arraywitharray:arry];

adding elements
[Arry2 addobject:@ "Guan Yu"];
NSLog (@ "%@", Arry2);

Insert
[Arry2 insertobject:@ "Liu Bei" atindex:0];


Delete
[Arry2 Removeobjectatindex:3];

Replace
[Arry2 replaceobjectatindex:0 withobject:@ "Sun Shangxiang"];

Swap the position of two elements
[Arry2 exchangeobjectatindex:0 Withobjectatindex:2];

Iterate through the elements inside the array
for (int i = 0; i < [Arry2 count]; i++) {
NSLog (@ "---%@", [Arry2 objectatindex:i]);
}
Quick Enumeration
For (NSString *string in Arry2) {//using for ... In the process of fast enumeration, the number of elements inside the set is not allowed to change.
NSLog (@ "%@", string);
}

String interception
Nsarray *arry = [@ "2015:08:10 17:45:00" componentsseparatedbystring:@ ":"];
NSLog (@ "%@", Arry);


#pragma mark-nsnumber: Value object
NSNumber *intnumber = [NSNumber numberwithint:20];
Nsarray *arry = [Nsarray arraywithobjects:intnumber, Nil];
NSLog (@ "%@", intnumber);
NSLog (@ "%d", [intnumber intvalue]); Convert a Value object to an object


NSNumber *number = [NSNumber numberwithint:20];
NSLog (@ "%p,%p", intnumber, number); Enjoy meta-mechanism, potential memory leaks


Nsrange rang = Nsmakerange (3, 9);
Nsvalue *value1 = [Nsvalue Valuewithrange:rang];
NSLog (@ "value =%@", value1);

NSLog (@ "loc =%lu", [value1 rangevalue].location);

Char *str = "1234";
Nsvalue *value2 = [Nsvalue valuewithpointer:str];
NSLog (@ "value2 =%@", value2);
NSLog (@ "value2 =%p", [value2 Pointervalue]);
NSLog (@ "----%@", Nsstringfromclass ([Book class]); To convert a class name to a string
NSLog (@ "====%@", Nsstringfromrange (rang)); To convert a struct to a string

OC----String array iOS learning-----crushing Knowledge points Summary

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.