Objective-C Programming Summary (Article 1) string operations

Source: Internet
Author: User

I 've been learning objective-C Programming for a while, and now it's over. Next, let's start programming in IOS. Previously, to avoid forgetting, I decided to spend a few days summing up what I learned before, saving my time for forgetting.

Simple syntaxes, such as class creation, init method rewriting, and attribute definition, are often used. If you forget a very small possibility, you will be too lazy to write. Start with the string operation today.

String operations are summarized as follows:

1. The String constant nsstring * string = @ "content"; and the string created by [nsstring stringwithstring] cannot be release forever. If it is a large String constant content, it is best to put it in the resource file for reading, rather than inProgramIs defined directly by constants.

2. string SEARCH:

Nsange range = [STR rangeofstring: searchingstring];

3. String replacement:

// Find: searching.

// RPL: the replacement.

Nsstring * Source = [nsstring stringwithcstring: "asdfasdfasdf" withencoding: nsutf8stringencoding];

Nsmutablestring * Mul = [Source mutablecopy];

Nsstring * result = [Mul stringbyreplacingoccurrancesofstring: Find withstring: RPL];

4. Split the string according to a specific character. I always think this name is very strange.

Nsarray * ary = [[@ "1, 2, 3, 4" componentsseperatedbystring: @ ","]; // The array [@ "1", @ "2 ", @ "3", @ "4"];

5. trim the string:

Nscharacterset * chset = [nscharacterset charactorsetwithcharactersinstring: @ ""];

Nsstring * STR = [@ "CT" stringbytrimmingcharactersinset: chset]; // The @ "CT" will be returned. If you leave xcodeCodePrompts and Automatic completion of the function, this is really unable to live. It seems that Apple was squeezed out by Microsoft at the beginning.

6. Get the encoding except the standard NS encoding:

Nsstringencoding ENC = cfstringconvertencodingtonsstringencoding (kcfstringencodinggb_18030_2000); // obtain the gb2312 encoding class.

If you still have ANSI or something, you just need to remember to use the cfstringconvertencodingtonsstringencoding function and kcfstringencoding. You can check it in the header file cfstringencodingext. h.

 

 

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.