Blackhorse programmer _ objective-C Foundation notes (1)

Source: Internet
Author: User
Struct

Nsange:

 

Used to indicate the range

 

Create

Nsange R1 = {2, 4}

Nsange r2 = {. Location = 2,. Length = 4}

Nsange R3 = nsmakerange (2, 4)

 

Search for the range of a string in Str

Nsstring * STR = @ "I love OC ";

Nsange range = [STR rangeofstring: @ "Java"]

Nslog (@ "location = % lD, length = % lD", range. Location, range. length)

 

If not found, length = 0, location = nsnotfound =-1

 

 

Nspoint:

 

Used to represent the coordinates of a point

Create

 

Cgpoint p1 = nsmakepoint (10, 10 );

Nspoint P2 = cgpointmake (20, 20 );

Indicates the origin

Cgpointzero = cgpointmake (0, 0)

 

Nssize:

 

Indicates the size of a two-dimensional plane.

 

Nssize S1 = cgsizemake (100, 50 );

Nssize S2 = nsmakesize (100, 50 );

Cgsize S3 = nsmakesize (200, 60 );

 

Cgrect:

 

Represents a specific dimension and position of a two-dimensional plane.

 

Cgrectr1 = cgrectmake (0, 0,100, 50 );

Cgrect r2 = {0, 0 },{ 100, 90 }};

Cgrect R3 = {p1, S2 };

 

Another method for defining cgrect

 

 

Cgrect myrect (cgfloat X, cgfloat y, cgfloat width, cgfloat height)

{

Cgrect rect;

Rect. Origin. x = X;

Rect. Origin. Y = y;

Rect. Size. width = width;

Rect. Size. Height = height;

}

 

Convert struct to string

Nsstring * STR = nsstringfrompoint (P1 );

Nsstring * STR = nsstringfromsize (S3 );

Nsstring * STR = nsstringfromrect (R1 );

Compare whether the two points are the same (x, y)

Bool B = cgpointequaltopoint (cgpointmake (10, 10), cgpointmake (10, 10 ))

Determines whether a point is in a region.

Bool b2 = cgrectcontainspoint (cgrectmake (50, 40,100, 50), cgpointmake (60, 45 ))

 

The premise of using these cgpointequaltopoint, cgrectcontainspoint, and other functions is to add the CoreGraphics framework.

 

Nsstring

 

String Creation

 

Nsstring * S1 = @ "Jack ";

Nsstring * S2 = [[nsstring alloc] initwithstring: @ "Jack"];

Nsstring * S3 = [[nsstring alloc] initwithformat: @ "Age is % d", 10];

C string> C string

Const char * c = [S4 utf8string];

Nsutf8stringencoding can be used in Chinese.

Nsstring * S5 = [[nsstring alloc] initwithcontentsoffile: @ "/users/Apple/desktop/1.txt" encoding: nsutf8stringencoding error: Nil];

 

String Export

 

Nsstring * STR = @ "4234234 ";

Nsurl * url = [nsurl fileurlwithpath: @ "/users/Apple/desktop/my2.txt"];

[STR writetourl: URL atomically: Yes encoding: nsutf8stringencoding error: Nil];

 

Or

[@ "Jack \ njack" writetofile: @ "/users/Apple/desktop/my.txt" atomically: Yes encoding: nsutf8stringencoding error: Nil]

 

Nsmutablestring

 

Variable string

 

Nsmutablestring * S1 = [nsmutablestring stringwithformat: @ "My age is 10"];

 

Splice content to the end of S1

[S1 appendstring: @ "11 12"];

Obtain the is range

Nsange range = [S1 rangeofstring: @ "is"];

Delete is

[S1 deletecharactersinrange: range];

 

Immutable strings can also be concatenated into two strings

Nsstring * S2 = [nsstring stringwithformat: @ "Age is 10"];

Nsstring * S3 = [S2 stringbyappendingstring: @ "11 12"];

 

Additional knowledge: nsurl

 

File: // local resource protocol header

Http: // network resource protocol header

 

Create a resource path

Nsurl * url = [[nsurl alloc] initwithstring: @ "file: // users/Apple/desktop/1.txt"] local resource

Nsurl * url = [nsurl fileurlwithpath: @ "/users/Apple/desktop/1.txt"] local resource

 

Converts a resource path to a string.

Nsstring * S6 = [[nsstring alloc] initwithcontentsofurl: URL encoding: nsutf8stringencoding error: Nil]

Blackhorse programmer _ objective-C Foundation notes (1)

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.