Iphone: How to use the first character of my text box?

In my iPhone application, I want to use the first character in a UITextField text.

How can I do that?

+4
source share
7 answers

Plain:

NSString *text = [textField text]; NSString *capitalized = [[[text substringToIndex:1] uppercaseString] stringByAppendingString:[text substringFromIndex:1]]; NSLog(@"%@ uppercased is %@", text, capitalized); 
+23
source

In the Builder interface (or IB integrated into Xcode 4), if you click on UITextField, you can set the behavior of the text and keyboard.

Xcode 4 IB

+15
source

NSString * capitalizedString = [textField.text capitalizedString];

+4
source

Here I suggest you try. Hope this will be helpful for you.

Go to xib, select the text box, then in the attribute inspector you got the header version, just select the words option

+1
source

If you set the text field in the nib file, select nib, you will see various "text input traits" in the attributes of the text field - the first one deals with capitalization.

see rjstelling answer .....

0
source

Set the value "Capitalization" in the attributes of the text field to "Offers".

0
source

Instead of tanking it separately and capitalizing, try this. Simple 1-line code.

 NSString *text = [textField text]; NSString *capText = [text capitalizedString]; // capitalizes only first alphabet. 
0
source

All Articles