Tag: nsstring

Why is this program faster in Python than Objective-C?

I got interested in this small example of an algorithm in Python for looping through a large word list. I am writing a few “tools” that will allow my to slice a Objective-C string or array in a similar fashion as Python. Specifically, this elegant solution caught my attention for executing very quickly and it […]

How to find matching words in two separate strings?

If there are two separate strings, we need to retrieve all words that are matching (in those strings), in an array. also this matching should be case insensitive. What will be the most efficient way to achieve this. For Example: NSString *s1 = @”Hello there, I want to match similar words.”; NSString *s2 = @”Do […]

Always getting the same height using sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:

The CGSize returned by sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: contains always the same height. Why is that, and is there a way around this? I want to align a string vertically and it may not be truncated, unless it can’t fit on a single line using the minimum font size. So I try to use this method to get […]

How to validate the empty string in Objective C?

I want to validate the string value after getting in the below parser delegate method I have tried like [string length]>0 ,(string !=NULL) in if condition still blank string is printed in the NSlog.So what is the efficient method to validate the sting.I have used the below code. – (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if […]

Remove all duplicate characters from NSString

How to do this using standard methods (without manual iteration through source string)? PS: At final I want to get sorted characters of source string. I tried to use NSCharacterSet, but can’t find a method to convert character set to string (without iterating the set).

Objective C NSString problem

I have a NSString that I need to examine character by character and: examine char perform calculation loop (until string ends) Any thoughts on the best way to do this? Do I need to convert the NSString to a NSArray or C string?

String comparison for localization

What is the difference between NSString‘s localizedCaseInsensitiveCompare: and localizedStandardCompare: methods? I read the reference but did not get a proper idea of which one to use.

Using a NSString to set a color for a label

I want to create a method and use a string value “redColor” to set the UIColor for a label. tableColorName is the NSString “redColor” and I tried to apply a selector to create the UIColor and apply it to my textLabel. Thanks -(void) changeLabelColor { SEL labelColor = NSSelectorFromString([NSString stringWithFormat:[@”%@”, tableColorName]]); UIColor *color = [[UIColor […]

How to count the number of uppercase characters in a NSString?

I’m trying to find out the best way to count the number of uppercase characters that are in a NSString. I know how to find out if a certain character is uppercase by using this code: NSString *s = @”This is a string”; BOOL isUppercase = [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[s characterAtIndex:0]]; What would be the best […]

Call a method on every word in NSString

I would like to loop through an NSString and call a custom function on every word that has certain criterion (For example, “has 2 ‘L’s”). I was wondering what the best way of approaching that was. Should I use Find/Replace patterns? Blocks? -(NSString *)convert:(NSString *)wordToConvert{ /// This I have already written Return finalWord; } -(NSString […]