how to get first three characters of an NSString?
How can I return the first three characters of an NSString?
- Why is != NSClassFromString(NSStringFromClass()) on OS X?
- Fetched Property in XCode Data Model Editor for minimum value
- When should I use NSURL instead of NSString and vice versa?
- NSButton background transparent after getting focus
- Can't Connect window to IBOutlet with storyboard
- Getting an array of a property from an object array
3 Solutions Collect From Internet About “how to get first three characters of an NSString?”
Be sure your string has atleast 3 ch.. o.e. it will crash the app.
Here are some other links to check NSsting operations…
First, you have to make sure that the string contains at least 3 characters:
NSString *fullString = /* obtain from somewhere */; NSString *prefix = nil; if ([fullString length] >= 3) prefix = [fullString substringToIndex:3]; else prefix = fullString;
substringToIndex: will throw an exception if the index you provide is beyond the end of the string.
the right way is:
text = [text substringToIndex:NSMaxRange([text rangeOfComposedCharacterSequenceAtIndex:2])];
substringToIndex of NSString is indexing by code unit, emoji takes two code units.
make sure check the index yourself.
- How is Associative Reference implemented?
- Warning: Attempt to present * on * which is already presenting (null)
- Programmatically change UITextField Keyboard type
- Core Image face detection broken on 64 bit iOS?
- can variables be set randomly when declaring them again?
- Unbalanced calls to begin/end appearance transitions for <UITabBarController: 0x197870>
- Xcode can't update to version 6.2
- Taking a picture from the camera and show it in a UIImageView
- How to make a .pkg that the Mac Installer will simply install (copy) files from?
- How to add ARC for specific file?
- Is it possible to discover Gimbal beacons with standard iOS libraries
- Drawing a grid in UIScrollView's subview allocates huge memory
- Swift 3 Breaks Cell For Row At Index Path
- Firebase Swift 3 Xcode 8 – iterate through observe results
- Swift 2.0 soap request with Alamofire send xml parameters