Get last path part from NSString
You can also use NSString *sub = [@”http://www.abc.com/news/read/welcome-new-gig/03276″ lastPathComponent];
You can also use NSString *sub = [@”http://www.abc.com/news/read/welcome-new-gig/03276″ lastPathComponent];
After doing some research, it looks like containsString is not a String function, but can be accessed by bridging to an NSString. Under Apple’s Documentation on Using Swift with Cocoa and Objective-C, it says that Swift automatically bridges between the String type and the NSString class. This means that anywhere you use an NSString object, … Read more
You can use stringWithFormat:, passing in a format of %c to represent a character, like this: char c=”a”; NSString *s = [NSString stringWithFormat:@”%c”, c];
This is a different approach. Find out the minimum size of the text so that it won’t wrap to more than one line. If it wraps to over one line, you can find out using the height. You can use this code: CGSize maximumSize = CGSizeMake(300, 9999); NSString *myString = @”This is a long string … Read more
unichar lastChar = [yourString characterAtIndex:[yourString length] – 1]; or if you want it as an NSString: NSString *lastChar = [yourString substringFromIndex:[yourString length] – 1];
unichar greekAlpha = 0x0391; NSString* s = [NSString stringWithCharacters:&greekAlpha length:1]; And now you can incorporate that NSString into another in any way you like. Do note, however, that it is now legal to type a Greek alpha directly into an NSString literal.
your_float = [your_string floatValue]; EDIT: try this: NSLog(@”float value is: %f”, your_float);
NSString *str=@”1,2,3,4″; [str stringByReplacingOccurrencesOfString:@”3,” withString:@””]; That will remove ALL occurrences of @”3,” in str. If you want to remove only the first occurrence of @”3,”: NSString* str = @”1,2,3,4″; NSRange replaceRange = [str rangeOfString:@”3,”]; if (replaceRange.location != NSNotFound){ NSString* result = [str stringByReplacingCharactersInRange:replaceRange withString:@””]; } Hope this helps.
In a general setting, retaining an object will increase its retain count by one. This will help keep the object in memory and prevent it from being blown away. What this means is that if you only hold a retained version of it, you share that copy with whomever passed it to you. Copying an … Read more
A C string is just like in C. char myCString[] = “test”; An NSString uses the @ character: NSString *myNSString = @”test”; If you need to manage the NSString’s memory: NSString *myNSString = [NSString stringWithFormat:@”test”]; NSString *myRetainedNSString = [[NSString alloc] initWithFormat:@”test”]; Or if you need an editable string: NSMutableString *myMutableString = [NSMutableString stringWithFormat:@”test”]; You can … Read more