Url minus query string in Objective-C

Since iOS 8/OS X 10.9, there is an easier way to do this with NSURLComponents. NSURL *url = [NSURL URLWithString:@”http://hostname.com/path?key=value”]; NSURLComponents *urlComponents = [[NSURLComponents alloc] initWithURL:url resolvingAgainstBaseURL:NO]; urlComponents.query = nil; // Strip out query parameters. NSLog(@”Result: %@”, urlComponents.string); // Should print http://hostname.com/path

NSString question – rangeOfString method

From the documentation of NSString -[NSString rangeOfString] Return Value An NSRange structure giving the location and length in the receiver of the first occurrence of aString. Returns {NSNotFound, 0} if aString is not found or is empty (@””). So it looks like: if ([@”abc” rangeOfString:@”d”].location == NSNotFound){ //Do something Is the Apple-approved way. EDIT: I … Read more

Getting the substring from a certain character in NSString

NSString *myString = @”ABCDE*FGHI”; NSArray *myArray = [myString componentsSeparatedByString:@”*”]; key 0 of myArray will contain @”ABCDE” key 1 will contain @”FGHI” If you want more than one character to be the separator, use componentsSeparatedByCharactersInSet: NSString *myString = @”ABCDE*FGHI-JKL”; NSArray *myArray = [myString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@”*-“]]; key 0 of myArray will contain @”ABCDE” key 1 will contain … Read more

How to create a NSString from a format string like @”xxx=%@, yyy=%@” and a NSArray of objects?

It is actually not hard to create a va_list from an NSArray. See Matt Gallagher’s excellent article on the subject. Here is an NSString category to do what you want: @interface NSString (NSArrayFormatExtension) + (id)stringWithFormat:(NSString *)format array:(NSArray*) arguments; @end @implementation NSString (NSArrayFormatExtension) + (id)stringWithFormat:(NSString *)format array:(NSArray*) arguments { char *argList = (char *)malloc(sizeof(NSString *) * … Read more

How to “pass on” a variable number of arguments to NSString’s +stringWithFormat:

initWithFormat:arguments: NSString *estr(NSString *format, …) { va_list args; va_start(args, format); NSString *s = [[[NSString alloc] initWithFormat:format arguments:args] autorelease]; va_end(args); return s; } they don’t seem to have a convenience constructor “stringWith…” version

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)