nsstring

Objective-C: NSString not being entirely decoded from UTF-8

你离开我真会死。 提交于 2019-12-20 02:57:23
问题 I'm querying a web server which returns a JSON string as NSData . The string is in UTF-8 format so it is converted to an NSString like this. NSString *receivedString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding]; However, some UTF-8 escapes remain in the outputted JSON string which causes my app to behave erratically. Things like \u2019 remain in the string. I've tried everything to remove them and replace them with their actual characters. The only thing I can

How to remove hexadecimal characters from NSString

折月煮酒 提交于 2019-12-20 02:56:16
问题 I am facing one issue related some hexa value in string, i need to remove hexadecimal characters from NSString. The problem is when i print object it prints as "BLANK line". And in debug mode it shows like : So how can i remove it from the string? EDIT Triming whitespace : result of NSLog is : 2015-12-14 15:37:10.710 MyApp [2731:82236] tmp :'' Database: Earlier question: how to detect garbage string value in ios? 回答1: As your dataset clearly has garbage values, You can use this method to

Best way to strike out a text

天大地大妈咪最大 提交于 2019-12-20 01:47:19
问题 What is the best solution so far for a strike out text on the iPhone? I heard of multiple solutions: Something with three20 Image as a subview UIWebView And something with a NSAttributedString , but I don't find a working example for that. 回答1: In iOS 6 we can use "NSMutableAttributedString" for use more different styles. NSString* cutText = @"This Line is strike out."; NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString:cutText]; // making text property

How could I substring an NSString to the third occurrence of a character?

戏子无情 提交于 2019-12-20 01:43:57
问题 I want to count the ',' characters and substring when it has been repeated 3 times. Input: 9,1,2,3,9 Output: 9,1,2 回答1: I am pretty sure something that specific would not have a build in method. Off the top of my head: for(unsigned int i = 0; i < [string length]; ++i) { if([string characterAtIndex:i] == ',') { ++commaCount; if(commaCount == 3) { return [string substringWithRange: NSMakeRange(0, i)]; } } } http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes

NSString retain count -1

走远了吗. 提交于 2019-12-20 01:41:46
问题 I want to print retain count of NSString in AppDelegate class in didFinishLaunchingWithOptions method NSString *str = [[NSString alloc] init]; NSLog(@"str retain count %d",[str retainCount]); but it always gives -1 instead of +1....why ??? 回答1: NSUIntegerMax means the returned object is immortal. This used to be in the docs, but has since been removed (because -retainCount is very discouraged). In MRC, some people would actually override -retainCount to prevent their singletons from ever

Replacing bad words in a string in Objective-C

£可爱£侵袭症+ 提交于 2019-12-20 01:10:34
问题 I have a game with a public highscore list where I allow layers to enter their name (or anything unto 12 characters). I am trying to create a couple of functions to filter out bad words from a list of bad words I have in a text file. I have two methods: One to read in the text file: -(void) getTheBadWordsAndSaveForLater { badWordsFilePath = [[NSBundle mainBundle] pathForResource:@"badwords" ofType:@"txt"]; badWordFile = [[NSString alloc] initWithContentsOfFile:badWordsFilePath encoding

Boxing of NSString stringWithFormat like NSNumber

浪尽此生 提交于 2019-12-19 21:59:13
问题 We can create an NSNumber like this NSNumber *number = [NSNumber numberWithFloat:4.5]; //or NSNumber *number = @(4.5); //or NSNumber *number = @4.5; I know we can convert to an NSString with the following statement NSString *string = @("stuff"); //equivalent of [NSString stringWithUTF8String] However, can we create an NSString like this? NSString *string = @(@"Name is:%@",name); //equivalent of [NSString stringWithFormat] 回答1: This is just off the top of my head. I do not think there's any

Simplest way to extract first Unicode codepoint of an NSString (outside the BMP)?

。_饼干妹妹 提交于 2019-12-19 21:54:09
问题 For historical reasons, Cocoa's Unicode implementation is 16-bit: it handles Unicode characters above 0xFFFF via "surrogate pairs". This means that the following code is not going to work: NSString myString = @"𠬠"; uint32_t codepoint = [myString characterAtIndex:0]; printf("%04x\n", codepoint); // incorrectly prints "d842" Now, this code works 100% of the time, but it's ridiculously verbose: NSString myString = @"𠬠"; uint32_t codepoint; [@"𠬠" getBytes:&codepoint maxLength:4 usedLength:nil

objective-c concatenate NSString

怎甘沉沦 提交于 2019-12-19 18:24:06
问题 I have problems to concatenate NSString. Each time I pushed a button I want that something ("aux") is added to my string ("myString"). so: NSString *aux = [NSString stringWithFormat: @"%d", buttonIndex]; myString=[NSString stringWithFormat:@"%@/%@",posTargetaText,aux]; aux = nil; The first time i pushed the button it works good but the second it doesn't work. Some help please? 回答1: So you can certainly use stringWithFormat , but why don't you use stringByAppendingString instead, since that's

How to remove common letters in two Strings in iOS SDK? [closed]

走远了吗. 提交于 2019-12-19 13:46:14
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . How can i remove common letters in two strings and generate a new string using remaining unique letters ? for example: String 1= Optimus Prime, String 2= Deja Thoras, new string should be: Djaha 回答1: Just enumerate through the characters in the string and delete matching ranges. Be sure to search