SubbuUSA
asked on
c# question
Friends,
I have a snippet which has to be separate method call and should return me two strings. I will send fullName as a parameter from an other method and it should do the split and return me fristname and lastname as separate strings.
I have a snippet which has to be separate method call and should return me two strings. I will send fullName as a parameter from an other method and it should do the split and return me fristname and lastname as separate strings.
if (!string.IsNullOrEmpty(fullName))
{
int nameSplit = fullName.LastIndexOf(' ');
if (nameSplit > 0){
eventFeedPerson.GroupEventPersonFirstName = fullName.Substring(0, nameSplit);
eventFeedPerson.GroupEventPersonLastName = fullName.Substring(nameSplit + 1);
}
else
{
eventFeedPerson.GroupEventPersonFirstName = fullName;
eventFeedPerson.GroupEventPersonLastName = string.Empty;
}
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Calling example:
string source = "John Doe";
string fn, ln;
SplitStrings(source, out fn, out ln);
ASKER
Thanks..your code was excellent
NP. Glad to help = )
you could return a class that contains first an last name as property.
Those properties you can match to your eventFeedPerson object
Open in new window