Quantcast
Channel: How to separate a first name and last name in c#? - Stack Overflow
Browsing all 7 articles
Browse latest View live

Answer by Muhammad Adnan for How to separate a first name and last name in c#?

Here is the most generalized solution for this issue.public class NameWrapper{ public string FirstName { get; set; } public string LastName { get; set; } public NameWrapper() { this.FirstName = "";...

View Article



Answer by Nicholas Carey for How to separate a first name and last name in c#?

Something like this works:string name = "Mary Kay Jones" ;Regex rxName = new Regex( @"^\s*(?<givenName>[^\s]*)(\s+(?<surname>.*))?\s*$") ;Match m = rxName.Match( name ) ;string givenName =...

View Article

Answer by Guffa for How to separate a first name and last name in c#?

Split the string with a limit on the number of substrings to return. This will keep anything after the first space together as the last name:string[] names = Names.ToString().Trim().Split(new...

View Article

Answer by Rami for How to separate a first name and last name in c#?

Modify the code to be something like:Match Names = Regex.Match(item[2], @"(((?<=Name:(\s)))(.{0,60})|((?<=Name:))(.{0,60}))", RegexOptions.IgnoreCase);if (Names.Success){ String[] nameParts =...

View Article

Answer by Matt Bodily for How to separate a first name and last name in c#?

UseString.indexof("")Andstring.lastindexof("")if they match there is one space. If they dont there is 2. I believe it returns 0 if there are no matches. Hope this helpseditif you use the indexes you...

View Article


Answer by gotnull for How to separate a first name and last name in c#?

string fullName = "John Doe";var names = fullName.Split('');string firstName = names[0];string lastName = names[1];The reason you're getting an error is because you're not checking for the length of...

View Article

How to separate a first name and last name in c#?

I am looking for how to get rid off below exception "Index was outside the bounds of the array." for the below case 2Aim: To separate the first name and last name (last name may be null some times)Case...

View Article
Browsing all 7 articles
Browse latest View live




Latest Images