Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get first three characters of an NSString?

How can I return the first three characters of an NSString?

like image 991
Christian Gossain Avatar asked Mar 14 '11 04:03

Christian Gossain


People also ask

How do you get the first character of a string in Objective C?

You want: NSString *firstLetter = [codeString substringToIndex:1];

What is NSString Objective c?

Like NSNumber, NSString is also immutable type. It's used to represent text in Objective-C. NSString provides built-in support for Unicode, which means that we can include UTF-8 characters directly in string literals.

What is NSString in swift?

A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.

Do I need to release NSString?

If you create an object using a method that begins with init, new, copy, or mutableCopy, then you own that object and are responsible for releasing it (or autoreleasing it) when you're done with it. If you create an object using any other method, that object is autoreleased, and you don't need to release it.


1 Answers

 mystr=[mystr substringToIndex:3]; 

Be sure your string has atleast 3 ch.. o.e. it will crash the app.

Here are some other links to check NSsting operations...

Link1

Link2

Apple Link

like image 135
GameLoading Avatar answered Sep 21 '22 06:09

GameLoading