iOS Learning Note---OC language fourth day

Source: Internet
Author: User
Tags what header

Array of strings

First, use the Apple Help document

Learn to use Apple to help? A document is a developer? a skill

Inherits from inherit?

Conforms to follow what protocol

Which framework the framework belongs to

Availability, when can I use it?

Declared in what header file?

Related Documents related document

Sample code?

Quickly open Help documents

In the code, hover the mouse over the class name or the Dharma name, option+? left mouse button, click

Reference the hyperlink into the Help? document.

You can also use command+? left mouse button, enter the header? file, view the interface section of the class.

Second, string

The Foudation framework is the basic framework for cocoa programming, iOS programming, including: strings, collections,??, time, and so on.

NSString and nsmutablestring-immutable strings and mutable strings

In the C language, strings are made up of char arrays of characters

In OC, the String class is made up of unichar (multibyte characters) and is powerful.

NSString

Immutable String class. Content and degree cannot be changed after NSString object is created

Common methods

To create a new string, you can make the instance method and the convenience constructor.

Gets the string length.

Determines whether the string starts or ends with the specified string.

The search string range.

String truncation (gets substring).

Stitching strings.

The replacement string.

String? comparison.

string and numeric type conversions.

? lowercase conversion operation.

#import <Foundation/Foundation.h>intMainintargcConst Char*argv[]) {/*    NSString *str1 = @ "Zhang San";    NSString *STR2 = [[NSString alloc] initwithformat:@ "hi,%@,%d years old", str1,29];//nsuinteger length = [str1 length];    NSLog (@ "%lu", [str2 length]);    NSString *STR3 = [nsstring stringwithformat:@ "Hai%@,%d", str1,29];        NSLog (@ "%@", STR3); NSLog (@ "%d", [str2 hasprefix:@ "HI"]);//The judgment string is prefixed with the xxx character NSLog (@ "%d", [str2 hassuffix:@ "old"]);//judging string with xxx character ending Nsrange ra    Nge = [str2 rangeofstring:@ "three"];    NSLog (@ "%lu%lu", range.location,range.length);    NSLog (@ "%@", [str2 substringfromindex:5]);//Intercept string NSLog (@ "%@", [str2 Substringtoindex:5]);    Nsrange R ={3,3};    NSLog (@ "%@", [str2 substringwithrange:r]);//Where to intercept, intercept how long the string NSLog (@ "%@", [str1 stringbyappendingstring:str2]);//string concatenation NSLog (@ "%@", [str1 stringbyappendingformat:@ "---%@", str2]);//String Format stitching NSLog (@ "%@", [str1    stringbyreplacingoccurrencesofstring:@ "three" withstring:@ "789456"]);//String substitution nsstring *STR4 = @ "Literary Youth"; NSString *STR5 = [STR4 stringbyreplacingoccurrencesofstring:@ "literary" withstring:@ "2B"];   NSLog (@ "%@", STR5); Output//2014-06-26 17:03:16.424 lessonstring[1358:303] 10//2014-06-26 17:03:16.426 lessonstring[1358:303] Hai Zhang San, 29//20 14-06-26 17:03:16.426 lessonstring[1358:303] 1//2014-06-26 17:03:16.426 lessonstring[1358:303] 1//2014-06-26 17:03:16.427 lessonstring[1358:303] 4 1//2014-06-26 17:03:16.427 lessonstring[1358:303], 29 years old//2014-06-26 17:03:16.427 lessonstring[1358:303] Hi, Zhang San//2014-06-26 17:03:16.428 lessonstring[1358:303] Zhang San//2014-06-26 17:03:16.428 LESSONSTRING[1358:303] Zhang San Hi, Zhang San, 29 years old//2014-06-26 17:03:16.429 lessonstring[1358:303] Zhang San---hi, Zhang San, 29 years//2014-06-26 17:03:16.429 lessonstring[1358:303] Zhang 789456//2014-06-26 17:03:16.429 lessonstring[1358:303] 2B Youth*/   /*nsstring *str11 = @ "Lanoukeji";    NSString *str12 = [NSString stringwithformat:@ "Lanoukeji"];    if ([Str11 Isequaltostring:str12]) {NSLog (@ "Str11 and Str12");    }else{NSLog (@ "different");    }//compares strings for equality nsstring *str13 = @ "123";    int a = [Str13 intvalue];        NSLog (@ "%d", a);    NSString *str14 = @ "Ni hao";    NSLog (@ "%@", [Str14 capitalizedstring]);//initial capital return 0; Output//2014-06-26 17:02:05.826 lessonstring[1347:303] Str11 and Str12//2014-06-26 17:02:05.827 lessonstring[1347:30 3] 123//2014-06-26 17:02:05.828 lessonstring[1347:303] Ni Hao*/

Nsmutablestring

Variable String class.

Subclass of the NSString class, the string created by this class is a dynamic, variable string that supports dynamic operations such as adding and deleting changes.

Nsmutablestring is NSString? Subclass, inherited by all? methods.

The modification of immutable strings is essentially a new string.

Immutable string modification methods start with a string and have a return value.

Variable string modification method does not return a value, modify the original string

Related Article

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.