Ilya Suzdalnitski
Ilya Suzdalnitski

Reputation: 53560

objective-c: how to convert an int to NSString

I am using the following code to get an alphabetic number of a first letter in a string:

toupper([ my_string characterAtIndex: 0 ] ) - 'A'

I need to do an inverse task - to convert an alphabetical number of a letter to a NSString.

What is the best way to do so?

Thank you in advance.

Upvotes: 3

Views: 6247

Answers (1)

Adam Rosenfield
Adam Rosenfield

Reputation: 400592

Use stringWithFormat::

// 0 ==> @"A", 25 ==> @"Z"
NSString *str = [NSString stringWithFormat:@"%c", theCharIndex + 'A'];

edited to include string identifier @

Upvotes: 11

Related Questions