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.