开发者

Inverting first and last name in objective-c?

开发者 https://www.devze.com 2023-03-28 23:03 出处:网络
I\'ve got a .plist that has the names of people that I want to use formatted like the following: <key>Name<开发者_开发问答/key>

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

精彩评论

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