<pre name= "code" class= "OBJC" >
1. The scope of the function, look at the structure: [Plain] View plaincopy typedef struct _NSRANGE {unsigned int Location unsigned int length; }nsrange;//where location indicates the starting position of the field for the range, and length indicates the number of elements contained within the range. For example: In the string "Objective-c is a cool language", the word "cool" can be represented by a range of loaction for 17,length 4. Perhaps because the Locatio field is not initialized, its value can be nsnotfound, which is used to denote a meaningless range. There are 3 ways to create a new Nsrange:[plain] view plaincopy (1) to assign a value directly to a field Nsrange range: Range.location = 17; Range.length = 4; (2) Applying the aggregation structure assignment mechanism of c nsrange range = {17,4}; (3) Using a shortcut function provided by Cocoa Nsmakerange (); Nsrange range = Nsmakerange (17,4); 2. Geometry data type: [Plain] View plaincopy (1) Nspoint and nssize, first look at their structure: typedef struct _NSPOI nt{float x; Float y;}nspoint; typedef struct _nssize{float width; float height; }nssize; (2) rectangular type nsrect typedef struct _nsrect{nspoint origin; Nssize size; }nsrect; (3) They also have: shortcut functions for creating data types, Nsmakepoint (), Nsmakesize (), and Nsmakerect (). 3. String type operation: <pre name= "code" class= "OBJC" ><span style= "font-family:arial, Helvetica, Sans-serif;" > (1) Create a string, in addition to the direct assignment to create a nsstring string, you can also pass: stringWithFormat method through the </span> Format strings and Parameters create NSString + (ID) stringWithFormat: (NSString *) format, ..... Examples are as follows: NSString *height; Height = [NSString stringWithFormat: @ "Your height is%d feet,%d inches", 5,11]; The resulting string was "Your height is 5 feet, 11inches". There are two places to note here, the first is the ellipsis behind this method, which means that the method can receive several other parameters separated by commas, and the second is that the method declaration begins with a + sign, which represents the class object that created the class, which we call the "factory method". (2) Get the string size: length, using the following method unsigned int length = [Height length]; This method can handle international strings with accuracy. Such as Russian, Chinese, Japanese and so on. (3) NSString string comparison operation: 1.-(BOOL) isequaltostring: (NSString *) astring; Use the following nsstring *thing1 = @ "Hello 2"; NSString *thing2; Thing2 = [NSString stringWithFormat: @ "Hello%d", 5]; if ([thing1 isequaltostring:thing2]) {NSLog (@ "They is the same!");} Note that this method compares the value of a pointer to a string, and "= =" compares a pointer value. 2.-(Nscomparisonresult) Compare: (NSString *) string; To use the following, first look at the Nscomparisonresult structure: typedef enum _nscomparisonresult{nsorderedascending =-1; Nsorderedsame, nsordereddescending}nscomparisonresult; Example: [@ "zoinks" Compare: @ "Jinies"] will return nsordereddescending (the character to the left is behind the right character) 3.-(Nscomparisonresult) COMpare: (NSString *) string options: (unsigned) mask; The options parameter is a bitmask, and you can use bits or operators to add an option tag. Examples are as follows: if ([Thing1 compare:thing2 Options:nscaseinsensitivesearch | Nsnumericsearch] = = nsorderedsame) {NSLog (@ "they match!");} (4) Whether the string contains any other string 1.-(BOOL) Hasprefix: (NSString *) astring;//Check if the string starts with another string-(bool) Hassuffix: (NSString *) astring;// Checks whether the string ends with another string-(Nsrange) rangeofstring: (NSString *) astring;//rangeofstring: When sent to a NSString object, the passed argument is the string to find, It returns a nsrange struct that tells you where to match the string and the number of strings that can match. Example: Nsrange range; NSString *filename = @ "Draft-chapter.pages"; Range = [FileName rangeofstring: @ "chapter"]; The returned Range.Start is 6,range.length 7. If the passed parameter is not found in the receive string, the Range.Start equals Nsnotfound. 5. Variability, NSString is immutable, which doesn't mean you can't manipulate them. Cocoa provides a subclass of NSString called nsmutablestring (a string that can be changed) (1)-(ID) stringwithcapacity: (unsigned) capacity; Note that this capacity is only a suggestion for nsmutablestring. Example: string = [nsmutablestring stringwithcapcity:42]; (2) with a variable string, you can perform various operations on it: 1.-(void) appendString: (NSString *) astring; 2.-(void) APpendformat: (NSString *) format, ...; Example: Nsmutablestring *string; string = [nsmutablestring stringwithcapacity:50]; [String appendString: @ "Hello there"]; [String AppendFormat: @ "Human%d!", 39]; The result of this code is that string is assigned "Hello there human 39!" 3.-(void) Deletecharactersinrange: (nsrange) range; We often put Deletecharactersinrange: and rangeofstring: Used together, example: nsmuablestring *friends; Friends = [nsmutablestring stringwithcapacity:50]; [Friends appendString: @ "JAmes Bethlynn Jack Evan"]; Next, find Jack's character range: Nsrange Jackrange; Jackrange = [Friends rangeofstring: @ "Jack"]; jackrange.length++;//the meaning of the sentence is that the following space is counted. [Friends Deletecharactersinrange:jackrange]; The result: "James Bethlynn Evan"
typedef struct _NSRANGE {unsigned int location; unsigned int length;} Nsrang
Where location indicates where the field holds the starting position of the range, and length indicates the number of elements contained within the range
The judgment of the iOS string