I am return RM00101 data from from a stored procedure, and I need to get First and Last name. I could simply split the CUSTNAME by spaces but is that the best way to do it? My concern is with names that may have more than a single space separating three or more words as a full name. Should I be concerned?
*This post is locked for comments
In case anyone else is looking for this, here is the code I wrote to get first and last from CUSTNAME.
string[] nameParts = strCUSTNAME.Split(' ');
string first=null, last=null;
if(nameParts.Length > 2)
last = nameParts[2];
else if (nameParts.Length > 1)
last = nameParts[1];
//first name is always element 0
if (nameParts.Length > 0)
first = nameParts[0];
If all you had to deal with was 2 word names, it would be very easy to do this. However, you have other things to consider:
1. What if a customer name is First Initial Last
2. First Middle Last
3. What if a customer name is a company name
4. First Initial[.] Last
The permutations of how a name can be written is the troubling part, not the splitting of the name in itself
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156