How do I convert HTML NSData to an NSString?

為{幸葍}努か 提交于 2019-12-21 18:34:34

问题


I'm using [NSData dataWithContentsOfURL:] to create two NSData instances and I want to compare these instances to gauge how different they are. Since they're both from the same website, using a string to find what is different will help me highlight the actual element(s) that has (have) changed. Is it possible to change this data to a string to find the difference?


回答1:


Try initWithData:encoding: method of NSString to create string with your data.

Exmp: NSString *str = [[NSString alloc] initWithData:someData encoding:NSUTF8StringEncoding]




回答2:


Why don't you use NSString stringWithContentsOfURL:encoding:error:



来源:https://stackoverflow.com/questions/6719890/how-do-i-convert-html-nsdata-to-an-nsstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!