immutable string Manipulation :
1.initWithFormat:. The initialization operation, where the effect of a direct assignment is the same as the method, for example:
1 NSString *string1 = [[NSString alloc] initWithFormat:@"iOS"];
2 NSString *string2 = @"iOS";
However, it is important to note that the second method declares a constant string, which is located in the constant area in memory.
2.length. Gets the length of the string, defined as
1 @property (readonly) Nsuinteger length;
By invoking the property: [string length] or string.length
3.isEqualToString:. Determines whether the contents of two strings are equal
4.compare:. To compare the size of two strings, you can look at the definition of the method:
1 -(Nscomparisonresult) Compare: (NSString *)string;
You can see that the method has a return value that looks at the definition of the return value:
1 typedef ns_enum (Nsinteger, nscomparisonresult) {nsorderedascending =-1L, Nsorderedsame, Nsordereddescending};
The return value is an enumeration type, where 1 indicates ascending, that is, the preceding string is smaller than the following string, and so on.
5. Get the substring:
A.substringfromindex:. followed by the subscript, that is, starting from the specified subscript to intercept the string.
B.substringtoindex:. followed by the subscript, that is, from the beginning to intercept the specified subscript.
Above two methods, one from the middle to the end, the other from the beginning to the middle.
C.substringwithrange:. Write a parameter of this type: (nsrange) range to see the definition of that type:
1 typedef struct _NSRange {
2 NSUInteger location;
3 NSUInteger length;
4 } NSRange;
The type is a struct, and the Nsmakerange method can pass in the correct parameters, representing the starting position and length, respectively.
6.stringByAppendingString:. Stitching the string, stitching the string in the argument to the front, note that the method will be the concatenation of the string as the return value, that is, the original two strings do not do anything .
7. Replace the string:
A.stringbyreplacingcharactersinrange:withstring:. Similar to the previous method of getting a substring, given a nsrange range, the subsequent string is replaced, even if the subsequent string is longer than the previous one.
B.stringbyreplacingoccurrencesofstring:withstring:. The method matches the string according to the first argument and replaces all occurrences with the second argument.
8. Type Conversion
Intvalue Charvalue in turn
9. Case
A.uppercasestring. Turn all capitals
B.lowercasestring. Turn all lowercase
C.capitalizedstring. Capitalize the first letter of each word
10. String verification
A.hasprefix:. Detects whether a string starts with a parameter, and the return value is bool
B.hassuffix:. Detects whether the string ends with a parameter, the return value is bool
Variable string manipulation:
1.initWithCapacity:. Variable string initialization, the parameter is allocated space, because the size of the variable string is not fixed, so according to the actual value, there is no rule can be filled with 0.
2.setString:. Sets the value of the string with the passed in parameter, overwriting the original content.
3.appendFormat:. Stitching strings, with stringbyappendstring: the same
4.deleteCharactersInRange:. Deletes a string based on a given nsrange
5.insertstring:atindex:. Inserts a string in the specified subscript, the first argument is the inserted string, and the second parameter is the inserted subscript
6.replacecharactersinrange:withstring:. Replaces a string within a specified range, the first parameter is a range of type Nsrange, and the second argument is a string that is required
Value object:
NSNumber
Because an array in OC can store different types of data, but the data must be objects, you need to store the base data type through a value object. Syntax: NSNumber *num = [NSNumber numberwithint:4];
The following methods can be changed depending on the type of the specific parameter.
You can also restore an object of type NSNumber * to a basic data type
[Num Intvalue]
Value objects can also be compared by compare: Method size
Nsvalue
Nsvalue can not only transform the basic data type, but also transform the structure and the object compared to NSNumber.
"Objective-c Study record" 22nd Day