🔒 Closed Full Name Parser

Status
Not open for further replies.

tamadsijuan

Honorary Poster
Help po mga master kung panu mas mapapa ikli yung code
salamat ng madame mga idol
kahit konting idea lang po malaking tulong na

ito para sa First Name cut ko na lang kasi sobrang haba nya hindi kasya
C#:
    public class functions
    {

        public string lcFullName { get; set; }
        public string lcFirstName { get; set; }
        public string lcMiddleName { get; set; }
        public string lcLastname { get; set; }
        public string lcSuffix { get; set; }

        public string getfirstname(string lcFullName)
        {
           // Debugger.Launch();

            string[] array = new string[] { " Sr.", " Sr", " Jr.", " Jr", " II", " III", " IV", " V", " VI", " CPA", " LL.M", " Ph.D", " Esq", " MBA", " MD" };

            foreach (string lcCurrent in array)
            {
                if (lcFullName.ToUpper().Contains(lcCurrent.ToUpper()))
                {
                    lcFullName = lcFullName.ToUpper().Replace(lcCurrent.ToUpper(), "");
                }

            }

            string[] words = lcFullName.ToUpper().Split(' '); // <-- Space character
            int numberOfWords = words.Length;

            if (numberOfWords == 3)
            {
                if (numberOfWords == 3)
                {
                    string[] fullname = lcFullName.Split(new Char[] { ' ' });
                    if (fullname[1].Length > 2)
                    {
                        string firstname = fullname[0] + " " + fullname[1];
                        lcFirstName = firstname;
                        lcMiddleName = null;
                        lcLastname = null;
                        lcSuffix = null;
                        return lcFirstName;
                    }
                    else if (fullname[1].Length == 2 && fullname[1].ToUpper().Contains('.'))
                    {
                        string firstname = fullname[0];
                        lcFirstName = firstname;
                        lcMiddleName = null;
                        lcLastname = null;
                        lcSuffix = null;
                        return lcFirstName;
                    }
                    else if (fullname[1].Length == 1)
                    {
                        string firstname = fullname[0];
                        lcFirstName = firstname;
                        lcMiddleName = null;
                        lcLastname = null;
                        lcSuffix = null;
                        return lcFirstName;
                    }
                    else if (fullname[2].Length >= 3)
                    {
                        string firstname = fullname[0];
                        lcFirstName = firstname;
                        lcMiddleName = null;
                        lcLastname = null;
                        lcSuffix = null;
                        return lcFirstName;
                    }
                }
            }

ito para sa Last Name
Code:
public string getlastname(string lcFullName)
        {
           //Debugger.Launch();
            //MessageBox.Show(lastname);
            string[] array = new string[] { " Sr.", " Sr", " Jr.", " Jr", " II", " III", " IV", " V", " VI", " CPA", " LL.M", " Ph.D", " Esq", " MBA", " MD" };

            foreach (string lcCurrent in array)
            {
                if (lcFullName.ToUpper().Contains(lcCurrent.ToUpper()))
                {
                    lcFullName = lcFullName.ToUpper().Replace(lcCurrent.ToUpper(), "");
                }

            }

            string[] words = lcFullName.ToUpper ().Split(' '); // <-- Space character
            int numberOfWords = words.Length;
            if (numberOfWords == 3)
            {
                string[] fullname = lcFullName.Split(new Char[] { ' ' });
                if (fullname[1].Length > 2)
                {
                    string lastname = fullname[2];
                    lcLastname = lastname;
                    lcMiddleName = null;
                    lcFirstName = null;
                    lcSuffix = null;


                }
                else if (fullname[1].Length == 2)
                {
                    string lastname = fullname[2];
                    lcLastname = lastname;
                    lcMiddleName = null;
                    lcFirstName = null;
                    lcSuffix = null;
                   
                }
                else if (fullname[1].Length == 1)
                {
                    string lastname = fullname[2];
                    lcLastname = lastname;
                    lcMiddleName = null;
                    lcFirstName = null;
                    lcSuffix = null;
                   
                }
ito for MI
Code:
public string getmiddlename(string lcFullName)
        {

            string[] array = new string[] { " Sr.", " Sr", " Jr.", " Jr", " II", " III", " IV", " V", " VI", " CPA", " LL.M", " Ph.D", " Esq", " MBA", " MD" };

            foreach (string lcCurrent in array)
            {
                if (lcFullName.ToUpper().Contains(lcCurrent.ToUpper()))
                {
                    lcFullName = lcFullName.ToUpper().Replace(lcCurrent.ToUpper(), "");
                }

            }

            string[] words = lcFullName.ToUpper ().Split(' '); // <-- Space character
            int numberOfWords = words.Length;
            if (numberOfWords == 3)
            {
                string[] fullname = lcFullName.Split(new Char[] { ' ' });
                if (fullname[1].Length > 2)
                {
                    lcFirstName = null;
                    lcMiddleName = null;
                    lcLastname = null;
                    lcSuffix = null;
                    return lcMiddleName;
                }
                else if (fullname[1].Length == 2)
                {
                    string middlename = fullname[1];
                    lcMiddleName = middlename;
                    lcFirstName = null;
                    lcLastname = null;
                    lcSuffix = null;
                    return lcMiddleName;
                }
                else if (fullname[1].Length == 1)
                {
                    string middlename = fullname[1];
                    lcMiddleName = middlename;
                    lcFirstName = null;
                    lcLastname = null;
                    lcSuffix = null;
                    return lcMiddleName;
                }
 
Status
Not open for further replies.

About this Thread

  • 0
    Replies
  • 270
    Views
  • 1
    Participants
Last reply from:
tamadsijuan

Trending Topics

Online now

Members online
1,112
Guests online
1,504
Total visitors
2,616

Forum statistics

Threads
2,293,278
Posts
29,082,929
Members
1,208,729
Latest member
Susay4220
Back
Top