专门做ppt的网站叫什么,wordpress需要开什么端口,企业网络营销为什么要选择外包?,360网站卖东西怎么做的做了不少时间的iOS开发了#xff0c;现在在阅读官方文档#xff0c;特意整理出来#xff0c;没任何技术含量#xff0c;纯粹是笔记形式#xff0c;希望对自己对大家有些帮助。 首先#xff0c;要理解NSString需要学习下字符编码#xff08;ASCii#xff0c;Unicode现在在阅读官方文档特意整理出来没任何技术含量纯粹是笔记形式希望对自己对大家有些帮助。 首先要理解NSString需要学习下字符编码ASCiiUnicodeUTF8的一些知识 可上维基百科搜索http://zh.wikipedia.org/zh-cn/UTF-8 现在开始分享iOS NSString的一些特性 NSString编码NSString的本质是基于Unicode编码的字符组成的数组 NSString创建如果你是用这种方式创建的那么temp对象是在编译时被创建并且在程序运行时一直存在永远不会被释放 NSString *temp Contrafibularity; 数据存储NSString不是设计用来存储任意序列的字节的如果想要这功能就用NSData 生成C String如果要用NSString产生一个C String建议使用UTF8String方法 const char *cString [Hello, world UTF8String]; 在iOS中CString是基于UTF-8编码的注意此时你得到的cString只是一个临时对象当自动释放发生后该对象会失效如果要继续使用需要重新申请内存并做拷贝 从File和URL中读写NSString 当读或写一个NSString时需要明确指定字符编码如果无法获取到编码信息官方文档建议如下 1.Try stringWithContentsOfFile:usedEncoding:error: orinitWithContentsOfFile:usedEncoding:error: (or the URL-based equivalents).These methods try to determine the encoding of the resource, and if successful return by reference the encoding used.
2.If (1) fails, try to read the resource by specifying UTF-8 as the encoding.
3.If (2) fails, try an appropriate legacy encoding. Appropriate here depends a bit on circumstances;it might be the default C string encoding, it might be ISO or Windows Latin 1, or something else, depending on where your data are coming from.
4.Finally, you can try NSAttributedStrings loading methods from the Application Kit (such asinitWithURL:options:documentAttributes:error:).These methods attempt to load plain text files, and return the encoding used.They can be used on more-or-less arbitrary text documents, and are worth considering if your application has no special expertise in text. They might not be as appropriate for Foundation-level tools or documents that are not natural-language text. NSScaner是一个字符串扫描工具非常好用运营一个官网的Demo应该就能做一些基本使用了 NSString *string Product: Acme Potato Peeler; Cost: 0.98 73\n\Product: Chef Pierre Pasta Fork; Cost: 0.75 19\n\Product:Chef Pierre Colander; Cost: 1.27 2\n;
NSCharacterSet *semicolonSet;
NSScanner *theScanner;NSString *PRODUCT Product:;
NSString *COST Cost:;NSString *productName;
float productCost;NSInteger productSold;
semicolonSet [NSCharacterSet characterSetWithCharactersInString:;];
theScanner [NSScanner scannerWithString:string];while ([theScanner isAtEnd] NO)
{if ([theScanner scanString:PRODUCT intoString:NULL] [theScanner scanUpToCharactersFromSet:semicolonSet intoString:productName] [theScanner scanString:; intoString:NULL] [theScanner scanString:COST intoString:NULL] [theScanner scanFloat:productCost] [theScanner scanInteger:productSold]){NSLog(Sales of %: $%1.2f, productName, productCost * productSold);}
} 创建标准文件路径 NSString *path /usr/bin/./grep;
NSString *standardizedPath [path stringByStandardizingPath];
// standardizedPath: /usr/bin/grep 补全相对路径 NSString *meHome [~me stringByExpandingTildeInPath];
// meHome /Users/me 获取Document目录 NSString *documentsDirectory;
NSArray *paths NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);if ([paths count] 0) {documentsDirectory [paths objectAtIndex:0];
} 路径Component操作 文件名匹配搜索假设路径“~/Demo/”下有如下文件ReadMe.txt readme.html readme.rtf recondite.txt test.txt NSString *partialPath ~/Demo/r;
NSString *longestCompletion;
NSArray *outputArray;unsigned allMatches [partialPath completePathIntoString:longestCompletioncaseSensitive:NOmatchesIntoArray:outputArrayfilterTypes:NULL];// allMatches 3
// longestCompletion ~/Demo/re
// outputArray (~/Demo/readme.html, ~/Demo/readme.rtf, ~/Demo/recondite.txt 转载于:https://www.cnblogs.com/mrfriday/p/3213518.html