Tag: nsstring

+ — what's the point?

As NSString strings are immutable, what is the value of the stringWithString: class method? I get the utility when used with NSMutableString, I just didn’t see the utility with the NSString class.

How to get substring of NSString?

If I want to get a value from the NSString @”value:hello World:value”, what should I use? The return value I want is @”hello World”.

How to get the width of an NSString?

I am trying to get the width of an NSString (ex. NSString *myString = @”hello”). Is there a way to do this? Thanks.

Storing and retrieving unsigned long long value to/from NSString

I have an unsigned long long value which I want to store into an NSString and retrieve from the string. Initially I have the value in an NSNumber and I am using this to get the string NSString *numStr = [NSString stringWithFormat:@”%llu”, [myNum unsignedLongLongValue]]; where myNum is an NSNumber. To get back the NSNumber from […]

Using an NSString in a switch statement

Is it possible to use an NSString in a switch statement? Or is it better to just use if / else if?

Using NSRegularExpression to extract URLs on the iPhone

I’m using the following code on my iPhone app, taken from http://tinyurl.com/remarkablepixels to extract all URLs from striped .html code. I’m only being able to extract the first URL, but I need an array containing all URLs. My NSArray isn’t returning NSStrings for each URL, but the objects descriptions only. How do I make my […]

With what should I replace the deprecated sizeWithFont: method?

I have a method that gives me the perfect size for a UITextView given a length of string (with the corresponding correct font size) : – (NSInteger) heightOfLabel:(NSString*) string { CGSize maximumLabelSize = CGSizeMake([[UIScreen mainScreen] bounds].size.width – 40, FLT_MAX); CGSize expectedLabelSize = [[NSString stringTrimmedForLeadingAndTrailingWhiteSpacesFromString:string] sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping]; return expectedLabelSize.height + 5; } In fact, […]

Replace all NSNull objects in an NSDictionary

I’m curious, I currently have an NSDictionary where some values are set to an NSNull object thanks to the help of json-framework. The aim is to strip all NSNull values and replace it with an empty string. I’m sure someone has done this somewhere? No doubt it is probably a four liner and is simple, […]

How to convert NSNumber to NSString

So I have an NSArray “myArray” with NSNumbers and NSStrings. I need them in another UIView so i go like this: – (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { DetailViewController *details = [[DetailViewController alloc] initWithNibName:@”DetailView” bundle:nil]; details.subjectText = [[myArray objectAtIndex:indexPath.row] objectForKey:@”subject”]; The subjectText works. But how can I get the NSNumbers out of it? (I actually need […]

Remove characters from NSString?

NSString *myString = @”A B C D E F G”; I want to remove the spaces, so the new string would be “ABCDEFG”.