nsstring

obj-c NSString and alloc / retain / release

萝らか妹 提交于 2019-12-11 04:52:34
问题 This is probably a question that is more about object alloc/retain/release, but I'll use NSString as an example. I'm aware that I can do: NSString* myString = [[NSString alloc] initWithString:@"Test"]; to essentially allocate and initialize a string referenced by my variable myString which I should later call [myString release] upon. However, if after I do this, I set it to some other string such as: myString = someOtherString; does that essentially create a memory leak because I've

NSString string based on CGSIZE

穿精又带淫゛_ 提交于 2019-12-11 04:37:00
问题 I have a long NSString and want to get only the string which gets fit in CGSize. Example: NSString *temp = @"jump jump jump jump jump jump"; CGSize = CGSizeMake(30,30); UIFont *font = [UIFont fontwithName:@"helviticaNueue" fontSize:18]; Please ignore the syntax. From above details can i get what NSString fits the CGSize and gets the ellipsis to. Below question only return the size/width: iOS 7 sizeWithAttributes: replacement for sizeWithFont:constrainedToSize 回答1: I just implemented this as a

how can I set substring of a NSString as bold in UILabel [duplicate]

久未见 提交于 2019-12-11 04:22:23
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Bold & Non-Bold Text In A Single UILabel? I want to know that how can I set substring of a NSString as bold in UILabel ? for example : I have a string in UILabel say, *Apply to a bill of $16 or more and I want to make " $16 " bold . Thanks.... 回答1: Simply use TTTAttributedLabel It's perfect for your purpose. 回答2: You could also UIWebView for displaying rich content in iPhone. Display Rich Text Using a UIWebView

remove leading 0 from a string, objective C [duplicate]

耗尽温柔 提交于 2019-12-11 04:19:47
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Removing leading zeroes from a string I need to remove 0 from the beginning of a string and prevent leading 0s when user input the number, how can I do it? For example: user input: 000090 display: 90 Thanks! 回答1: One approach is to use an NSScanner : NSString *string = @"000090"; NSCharacterSet *nonzeroNumberCharacterSet = [NSCharacterSet characterSetWithCharactersInString:@"123456789"]; NSScanner *scanner =

Grab NSString from Parse.com and paste it into UILabel

不羁的心 提交于 2019-12-11 03:56:11
问题 I'd like to grab a NSString from the Parse.com and paste it into a Label in my iOS App. Does anyone know how to do so ? I'm having massive problems with it :/ Thanks in advance 回答1: The counter-question is "Which NSString do you want to get"? I assume it's some property of a PFObject that you want to display, right? What makes this property so interesting? Let's say you want to display the title of a Book whose author is Hemmingway . First you want to find the object: PFQuery *query =

Objective-C decode quoted printable text

元气小坏坏 提交于 2019-12-11 03:36:27
问题 Is there any efficient (for text files > 5MB) quoted printable decoder written in C? I need such a decoder in an iOS project. At the meanwhile I am using a high level decoder which is way too slow. It takes up to 10 minutes on device to decode a 5MB file: - (NSString *)decodedQuotedPrintable:(NSString *)string { NSMutableString *decodedString = string.mutableCopy; [decodedString replaceOccurrencesOfString:@"=\r\n" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0,

Objective-C Calculating string value

夙愿已清 提交于 2019-12-11 03:21:26
问题 This is my main: int x=0; NSString *new=[[NSString alloc]initWithString:@"9+4"]; x=[new intValue]; NSLog(@"hi %i",x); This results in 9.. .since giving the intValue of a string will read only numbers and stops when the character is not a digit. So how can i print the result of my string and get a 13 instead?? 回答1: Change this line NSString *new=[[NSString alloc]initWithString:@"9+4"]; to NSString *new=[NSString stringWithFormat:@"%f",9+4]; 回答2: Actually, NSExpression was made just for this:

Get most-occurring NSString in an array

纵然是瞬间 提交于 2019-12-11 03:11:36
问题 Given an array of NSString s which have several repeated copies: AAA BBB AAA AAA BBB BBB BBB BBB CCC What's the easiest way to get the string which is most occurring? 回答1: Use NSCountedSet and then find the largest countForObject: . NSCountedSet *bag = [[NSCountedSet alloc] initWithArray:myArray]; NSString *mostOccurring; NSUInteger highest = 0; for (NSString *s in bag) { if ([bag countForObject:s] > highest) { highest = [bag countForObject:s]; mostOccurring = s; } } Checking the result:

Checking if a nsstring matches another string

若如初见. 提交于 2019-12-11 03:02:55
问题 Suppose I have a string "167282". How can I check if the string contains "128"? Is there any provision to know the percentage of the 2nd string that matches the first string? (If all the characters of the 2nd string are present in the first string or not.) Please help and thanx in advance. 回答1: Use the following: NSString *compareString = @"128"; NSCharacterSet *compareCharSet = [NSCharacterSet characterSetWithCharactersInString:@"167282"]; NSUInteger strLen = [compareString length];

Add spaces between words in spaceless string

≯℡__Kan透↙ 提交于 2019-12-11 02:59:56
问题 I'm on OS X, and in objective-c I'm trying to convert for example, "Bobateagreenapple" into "Bob ate a green apple" Is there any way to do this efficiently? Would something involving a spell checker work? EDIT: Just some extra information: I'm attempting to build something that takes some misformatted text (for example, text copy pasted from old pdfs that end up without spaces, especially from internet archives like JSTOR). Since the misformatted text is probably going to be long... well, I'm