Tip: Ns:nextstep cg:coregraphics
NSString: Immutable string nsmutablestring: mutable string
URL local file header: file://URL Network File header:/http
int main (int argc, const char * argv[]) {
int age = 10;
1. Creation of strings
NSString *s1 = @ "as God name";
NSString *s2 = [[NSString alloc] initwithstring:@ "Welcome to learn OC"]; Not used
NSString *S3 = [[NSString alloc] initwithformat:@ "Welcome to learn oc, age =%d", age]; Not used
NSString *S4 = [NSString stringwithformat:@ ' Welcome to learn oc, age =%d ', age];
C String---OC string
NSString *S5 = [[NSString alloc] initwithformat:@ "Welcome to learn OC"];
OC string---C string
const char *S5 = [S4 utf8string];
Reading a string from a file
NSString *S6 = [NSString stringwithcontentsoffile:@ "/users/apple/desktop/one.txt" encoding:nsutf8stringencoding Error:nil];
Read the URL string
Nsurl *url = [[Nsurl alloc] initwithstring:@ "File:///Users/apple/Desktop/one.txt"]; Creating a URL Path
Nsurl *URL2 = [Nsurl fileurlwithpath:@ "/users/apple/desktop/one.txt"]; Creating a URL Path
Reading a string from the URL path
NSString *S7 = [[NSString alloc] initwithcontentsofurl:url2 encoding:nsutf8stringencoding Error:nil];
NSLog (@ "%@", S7);
Writing a string to a file
NSString *S8 = @ "Welcome to learn OC";
Nsurl *URL3 = [[Nsurl alloc] initwithstring:@ "File:///Users/apple/Desktop/three.txt"];
[S8 writetofile:url3 atomically:yes encoding:nsutf8stringencoding Error:nil];
Nsmutablestring
nsmutablestring *S10 = [nsmutablestring stringwithformat:@ "Welcome to learn OC"];
[S10 appendstring:@ "Welcome to learn iOS development"]; Stitching the contents to the back of the S1
NSString *S11 = [NSString stringwithformat:@ "Welcome to my Blog"];
NSString *s12 = [S2 stringbyappendstring:@ "and other ..."]; Add a string after S11
Get string length
Nsuinteger length = Str.length
Gets the character of a position in a string
Unichar c = [str characteratindex:1];
return 0;
}
The NSString of Oc--foundation