Objective-C learning record 4

Source: Internet
Author: User

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)

 

 
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.