Some methods of string usage:
1. Create a dictionary nsstring variable string, and nsmutablestring immutable string. They are both objective objects.
Char * STR is an array of letters.
2. String formatting: stringwithformat, which is used to format any int, char double, float, and other internal types.
3. stringwithstring value assignment is similar to this,
Nsstring * STR = @ "I am me! ";
4. stringwithuf8string format for converting strings to UTF-8
5. connect two strings together stringbyappendingformat
6. strings are equal, and isw.tostring --- they are completely equal, case sensitive.
Hasprefixe matches the string header. hassuffix matches the tail.
-(Void) viewdidload {[Super viewdidload]; nsstring * str0 = @ "Chinese my name is xuanyusong"; nsstring * temp = @ "is"; nsange rang = [str0 rangeofstring: temp]; nslog (@ "index of the start point of the searched string in str0 is % d", rang. location); nslog (@ "the index of the string to be searched in str0 is % d", rang. location + rang. length); // Replace the string in the search with a new string nsstring * STR = [str0 stringbyreplacingcharactersinrange: rang withstring: @ ""]; nslog (@ "Replace the string with % @", STR); // Replace "" in the string with * STR = [str0 stringbyreplacingoccurrencesofstring: @ "" withstring: @ "@"]; nslog (@ "after replacement, the string is % @", STR );
7. Search for and replace the string.
Stringbyreplacecharacterinrange
Find all replicas: stringbyreplaceoccurencesofstring.
Extended: You can use the following method to replace the entire string and set the region to be replaced. ONS: <# (nsstringcompareoptions) #> range: <# (nsange) #> stringbyreplacingoccurrencesofstring :( nsstring *) withstring :( nsstring *) Options :( nsstringcompareoptions) range :( nsange)