nsstring

Is there a way to “auto detect” the encoding of a resource when loading it using stringFromContentsOfURL?

爱⌒轻易说出口 提交于 2019-12-01 10:38:29
Is there a way to "auto detect" the encoding of a resource when loading it using stringFromContentsOfURL? The current (non-depracated) method, + (id)stringWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)enc error:(NSError **)error; , wants a URL encoding. I've noticed that getting it wrong does make a difference for what I want to do. Is there a way to check this somehow and always get it right? (Right now I'm using UTF8.) Dave.B I'd try this function from the docs Returns a string created by reading data from a given URL and returns by reference the encoding used to interpret the

saddas

廉价感情. 提交于 2019-12-01 10:23:40
结对情况: 刘晓翔博客 翁世豪博客 Github项目地址 具体分工: 前后端交互——刘晓翔 核心算法——翁世豪 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning · 计划 200 150 Estimate · 估计这个任务需要多少时间 3000 4000 Development · 开发 1000 800 Analysis · 需求分析 (包括学习新技术) 600 500 Design Spec · 生成设计文档 200 150 Design Review · 设计复审 60 80 Coding Standard · 代码规范 (为目前的开发制定合适的规范) 200 400 Design · 具体设计 1000 1200 Coding · 具体编码 2000 2200 Code Review · 代码复审 300 300 Test · 测试(自我测试,修改代码,提交修改) 300 500 Reporting · 报告 300 400 Test Repor · 测试报告 300 400 Size Measurement · 计算工作量 100 60 Postmortem & Process Improvement Plan · 事后总结, 并提出过程改进计划 200 120 = · 合计 3500

第二次结对编程作业

天大地大妈咪最大 提交于 2019-12-01 10:22:54
结对情况: 刘晓翔博客 翁世豪博客 Github项目地址 具体分工: 前后端交互——刘晓翔 核心算法——翁世豪 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning · 计划 200 150 Estimate · 估计这个任务需要多少时间 3000 4000 Development · 开发 1000 800 Analysis · 需求分析 (包括学习新技术) 600 500 Design Spec · 生成设计文档 200 150 Design Review · 设计复审 60 80 Coding Standard · 代码规范 (为目前的开发制定合适的规范) 200 400 Design · 具体设计 1000 1200 Coding · 具体编码 2000 2200 Code Review · 代码复审 300 300 Test · 测试(自我测试,修改代码,提交修改) 300 500 Reporting · 报告 300 400 Test Repor · 测试报告 300 400 Size Measurement · 计算工作量 100 60 Postmortem & Process Improvement Plan · 事后总结, 并提出过程改进计划 200 120 = · 合计 3500

How to compare A to Á on the iPhone

南楼画角 提交于 2019-12-01 09:50:31
I need to compare 2 strings, looking at the first letter only. Is there a method to compare A to Á, and recognize it as A, without the ´ ? NSString has a diacritic-insensitive comparison mode which will do what you're after. // should return NSOrderedSame, i.e. identical [@"Apple" compare:@"Ápple" options:NSDiacriticInsensitiveSearch] If you want it to be case-insensitive as well: // ditto [@"APPLE" compare:@"Ápple" options:NSDiacriticInsensitiveSearch | NSCaseInsensitiveSearch] 来源: https://stackoverflow.com/questions/4418997/how-to-compare-a-to-%c3%81-on-the-iphone

MGJRouter源码解析及使用方法

╄→гoц情女王★ 提交于 2019-12-01 09:48:12
MGJRouter源码解析 MGJRouter是实现iOS组件间交互的工具之一,路由的使用降低了不同模块之间的耦合度,提高代码的复用率以及不同模块间重组的灵活度,下面我就针对MGJRouter说一下自己的理解: 注册 routes主要用于存储已经注册过的路径及block @property (nonatomic) NSMutableDictionary *routes; 下面三个方法是注册时对URL进行递归遍历以及对block进行存储 - (void)addURLPattern:(NSString *)URLPattern andHandler:(MGJRouterHandler)handler { //解析当前 URL 并转化出字典存贮在self.routes中 NSMutableDictionary *subRoutes = [self addURLPattern:URLPattern]; //将block存入到字典中 if (handler && subRoutes) { subRoutes[@"_"] = [handler copy]; } } - (void)addURLPattern:(NSString *)URLPattern andObjectHandler:(MGJRouterObjectHandler)handler { NSMutableDictionary

using UITextPosition, get previous character from textInRange

一笑奈何 提交于 2019-12-01 08:10:16
I've been searching high and low and can't figure out how to do this. Lets say I have a string like this: NSString *string = @"&foo !foo"; What I'm trying to do is differentiate between the two foos (sounds funny haha) inside a text view. When I click on one, I want to know which (& or !) comes before it. Here's how I'm getting the word: UITapGestureRecognizer *recognizer = (UITapGestureRecognizer *)sender; UITextView *TV = (UITextView*)recognizer.view; CGPoint location = [recognizer locationInView:TV]; location.y += TV.contentOffset.y; UITextPosition *tapPosition = [TV closestPositionToPoint

Converting hex string to hex data

旧街凉风 提交于 2019-12-01 08:09:12
I currently have an NSString containing hex values. I need to convert this NSString object into an NSData object, without changing its contents at all. I use this code to "parse" the debug output of an NSData object (what you get in the console if you just NSLog an NSData object) back into NSData: -(NSData*) bytesFromHexString:(NSString *)aString; { NSString *theString = [[aString componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] componentsJoinedByString:nil]; NSMutableData* data = [NSMutableData data]; int idx; for (idx = 0; idx+2 <= theString.length; idx

Pointers on Objective-c

孤人 提交于 2019-12-01 07:47:50
From what I understand (and please correct me if I'm wrong): int x, count = 10; int *hello; hello = &count; x = *hello; Here the variables x and count are declared to be of type integer. Additionally, the variable count is assigned the value of 10. hello is a pointer to type integer. hello is then assigned the address of count. In order to access the value of count, hello must have an asterisk in front of it, ie, *hello. So, x is assigned the value of whatever is in count and in this case, 10. However... Fraction *myFraction = [[Fraction alloc] init]; [myFraction someMethod]; Here, if I

Function to detect the NSStringEncoding from NSURLResponse?

耗尽温柔 提交于 2019-12-01 07:32:39
问题 I just wanted to know if there is any existing category or any sort of function that will return me NSStringEncoding constant out of NSURLResponse object . The issue I am facing at the moment is as I have hardcoded the encoding to NSUTF8StringEncoding when I convert the web service response data to String then it actually causes an issue , as my web service sometimes returns the response encoded in UTF8 and sometimes encoded in ASCII ( well I am not too sure about all the encodings though but

IOS:Convert string to hexadecimal array

时光怂恿深爱的人放手 提交于 2019-12-01 06:53:54
问题 i have string representing data .i need to convert those data to the hex array .By using the hex array data i can pass it to the CRC for writing to the peripheral My string data is like this NSString *stringsdata=@"helloworld1234567812345q"; i need to convert to hex format array like {0x0h,0x0e............0x0q}. so by using this array i can keep the data in the crc and write it to the peripheral data as Byte comm[24]; comm[0]=0x01; comm[1]=0x30; comm[2]=0x62; comm[3]=0x00;................