开发者

Inverting first and last name in objective-c?

I've got a .plist that has the names of people that I want to use formatted like the following:

<key>Name<开发者_开发问答/key>
<string>Doe, John</string>

I would really like it if the names would show up as John Doe instead of Doe, John. Similar to the way that you get rid of spaces in links, is there a method that I can use to easily accomplish this?

Thanks in advance!


This seems like fairly simple string processing. My Objective-C is a but rusty, but the following should work (untested):

NSString *name = @"Doe, John";
NSArray *lastFirst = [name componentsSeparatedByString: @", "];
NSString *formattedName = [[[lastFirst objectAtIndex:1] stringByAppendingString: @" "] stringByAppendingString:[lastFirst objectAtIndex:0]];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜