工程图:
此代码需要导入第三方库ChineseToPinyinDemo.
代码:
#import "ViewController.h" #import "ChineseToPinyin.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.title=@"汉字转拼音"; NSString *pinYinString=[ChineseToPinyin pinyinFromChiniseString:@"我爱你"]; NSLog(@"---拼音---%@-----",pinYinString); NSLog(@"--第一个字母-%@-----",[pinYinString substringToIndex:1]); }
输出:
2014-12-18 10:11:51.168 ChineseToPinyinDemo[1832:66705] ---拼音---WOAINI----- 2014-12-18 10:11:51.169 ChineseToPinyinDemo[1832:66705] --第一个字母-W-----