Home Tutorial Iphone Examples NSString CapitalizedString - Iphone example

 
 

Share on Google+Share on Google+
NSString CapitalizedString - Iphone example
Posted on: September 3, 2009 at 12:00 AM
Advertisement
In this example, we are going to show you how to change the first character of the given string into uppercase.

NSString CapitalizedString - Iphone example

Converting a first character of string to upper case (case changes): In this example, we are going to show you how to change the first character of the given string into uppercase. Create a simple "window based" application and place a button on it(connection with file Owner is req.). Button is required to give a action otherwise it will not show anything.

Syntax of NSString CapitalizedString:

NSString *firstCapChar = [[String substringToIndex:1] capitalizedString];
NSString
*cappedString = [String stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstCapChar];

Note: capitalizedString is used to convert first character of string into upper case.

Now let's explore the code:

capitalizefirstcharAppDelegate.h

#import <UIKit/UIKit.h>  
@interface capitalizefirstcharAppDelegate : 
NSObject <UIApplicationDelegate> { 
UIWindow *window; 
IBOutlet UIButton *button; 
NSString *string; 
} 
@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet UIButton *button; 
@property (nonatomic, retain) NSString *string; 
-(IBAction)captlizedString:(id)sender; 
@end

capitalizefirstcharAppDelegate.m

#import "capitalizefirstcharAppDelegate.h" 
@implementation capitalizefirstcharAppDelegate 

@synthesize window, button, string; 
-(IBAction)captlizedString:(id)sender; 
{ 
NSString *string1 = @"rose"; 
NSString *firstCapChar = 
[[string1 substringToIndex:1] capitalizedString]; 
NSString *cappedString = 
[string1 stringByReplacingCharactersInRange
:NSMakeRange(0,1) withString:firstCapChar]; 
NSLog(cappedString); 
} 
- (void)applicationDidFinishLaunching:(UIApplication *)application { 
// Override point for customization after application launch 
[window makeKeyAndVisible]; 
} 
- (void)dealloc { 
[window release]; 
[button release]; 
[super dealloc]; 
} 
@end

NSString capitalizedString will look like the given image...

 

Download the Source Code 

Advertisement

Related Tags for NSString CapitalizedString - Iphone example:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 3, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com