nsstring

Converting HTML text into plain text using Objective-C

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have huge NSString with HTML text inside. The length of this string is more then 3.500.000 characters. How can i convert this HTML text to NSString with plain text inside. I was using scanner , but it works too slowly. Any idea ? 回答1: It depends what iOS version you are targeting. Since iOS7 there is a built-in method that will not only strip the HTML tags, but also put the formatting to the string: Xcode 9/Swift 4 if let htmlStringData = htmlString.data(using: .utf8), let attributedString = try? NSAttributedString(data: htmlStringData,

NSString tokenize in Objective-C

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: What is the best way to tokenize/split a NSString in Objective-C? 回答1: Found this at http://borkware.com/quickies/one?topic=NSString (useful link): NSString * string = @ "oop:ack:bork:greeble:ponies" ; NSArray * chunks = [ string componentsSeparatedByString : @ ":" ]; Hope this helps! Adam 回答2: Everyone has mentioned componentsSeparatedByString: but you can also use CFStringTokenizer (remember that an NSString and CFString are interchangeable) which will tokenize natural languages too (like Chinese/Japanese which don't split words

Creating NSData from NSString in Swift

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to ultimately have an NSMutableURLRequest with a valid HTTPBody , but I can't seem to get my string data (coming from a UITextField ) into a usable NSData object. I've seen this method for going the other way: NSString(data data: NSData!, encoding encoding: UInt) But I can't seem to find any documentation for my use case. I'm open to putting the string into some other type if necessary, but none of the initialization options for NSData using Swift seem to be what I'm looking for. 回答1: In Swift 3 let data = string.data(using: .utf8

Rebuild an NSArray by grouping objects that have matching id numbers?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have an NSArray and each object in the array has a groupId and a name. Each object is unique but there are many with the same groupId. Is there a way i can tear the array apart and rebuild it so that the names are grouped into a single object with the corresponding groubId? Here is what the array currently looks like: 2013 - 03 - 12 20 : 50 : 05.572 appName [ 4102 : 702 ] the array : ( { groupId = 1 ; name = "Dan" ; }, { groupId = 1 ; name = "Matt" ; }, { groupId = 2 ; name = "Steve" ; }, { groupId = 2 ; name = "Mike" ; }, {

Rebuild an NSArray by grouping objects that have matching id numbers?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an NSArray and each object in the array has a groupId and a name. Each object is unique but there are many with the same groupId. Is there a way i can tear the array apart and rebuild it so that the names are grouped into a single object with the corresponding groubId? Here is what the array currently looks like: 2013-03-12 20:50:05.572 appName[4102:702] the array: ( { groupId = 1; name = "Dan"; }, { groupId = 1; name = "Matt"; }, { groupId = 2; name = "Steve"; }, { groupId = 2; name = "Mike"; }, { groupId = 3; name = "John"; }, {

Objective-C sample code for HMAC-SHA1 [closed]

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need to generate HMAC-SHA1 in Objective C. But i didnt find anything that works. I tried with CommonCrypto, using CCHMAC, but didnt works. I need to generate a hmac and after generate HOTP number. Somebody have any example code in Objective C or C? 回答1: Here's how you generate an HMAC using SHA-256: NSString *key; NSString *data; const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding]; const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding]; unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH]; CCHmac(kCCHmacAlgSHA256,

Objective C, Thread 1 Program Received Signal SIGABRT [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:07:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: What does this mean? “'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X” 64 answers I am trying to compile and run a simple tutorial for an Objective C app using Interface Builder. I am using Xcode 4.0.2 and simulating on iOS (iPhone) 4.3 http://www.switchonthecode.com/tutorials/creating-your-first-iphone-application-with-interface-builder When I build the project, it builds alright but once the app tries to run it crashes with: int main(int argc, char

Split an NSString into an array in Objective-C

≯℡__Kan透↙ 提交于 2019-12-03 02:06:45
How can I split the string @"Hello" to either: a C array of 'H' , 'e' , 'l' , 'l' , 'o' or: an Objective-C array of @[@"H", @"e", @"l", @"l", @"o"] If you're satisfied with a C array of char s, try: const char *array = [@"Hello" UTF8String]; If you need an NSArray, try: NSMutableArray *array = [NSMutableArray array]; NSString *str = @"Hello"; for (int i = 0; i < [str length]; i++) { NSString *ch = [str substringWithRange:NSMakeRange(i, 1)]; [array addObject:ch]; } And array will contain each character as an element of it. Try this : - (void) testCode { NSString *tempDigit = @"12345abcd" ;

Objective C, Thread 1 Program Received Signal SIGABRT [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: What does this mean? “'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X” 64 answers I am trying to compile and run a simple tutorial for an Objective C app using Interface Builder. I am using Xcode 4.0.2 and simulating on iOS (iPhone) 4.3 http://www.switchonthecode.com/tutorials/creating-your-first-iphone-application-with-interface-builder When I build the project, it builds alright but once the app tries to run it crashes with: int main(int argc, char

How to load local html file into UIWebView

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to load a html file into my UIWebView but it won't work. Here's the stage: I have a folder called html_files in my project. Then I created a webView in interface builder and assigned an outlet to it in the viewController. This is the code I'm using to append the html file: -(void)viewDidLoad { NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"html" inDirectory:@"html_files"]; NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile]; [webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@