What im and trying to do is take the first four letters of a last name and the first letter in the first name which are in a textbox to use for a user name that im trying to generate but how do i go about doing this is very i unclear to me.If you need more info let me know, this is what i have so far:

 public partial class Create_Participant : Form
    {
        public Create_Participant()
        {
            string name, address, city, state, chapNum, PType;
            name = txtName.Text;
            address = txtAddress.Text;
            city = txtCity.Text;
            state = txtState.Text;
            chapNum = txtChapNum.Text;
            InitializeComponent();

            if (radAdvisor.Checked == true)
            {
                PType = "a";//Advisor
            }
            else if (radGuest.Checked == true)
            {
                PType = "g";//Guest
            }
            else if (radMember.Checked == true)
            {
                PType = "m";//Member
            }
            else
            {
                MessageBox.Show("Participant type is required.", "Create Participant");
            }
            string[] Name = {txtName.Text};
            for(int i = 0; i < name.Length; i++)
            {
                name[i] = 

            }
            StreamWriter Guests = new StreamWriter("Guests Registered.txt");
            Guests.WriteLine("+" + name + "\r\n-a" + 

    }
}

Hey there again:

How's this?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string name = "Firstname Lastname";
            string code  = generateCode(name) ;
            Console.WriteLine("Code : " + code);
            Console.ReadKey();
        }
        private static string generateCode(string n)
        {
            string[] words = n.Split(' ');
            return words[1].Substring(0, 4) + words[0].Substring(0, 1);

        }
    }
}

you can Use the substring and indexof functions. like
item = item.Substring(1, item.Length 4)
or you can try

' try this
<%
dim myString
myString = "hello.txt"
%>

<tr><%=Right(myString, 4)%></tr>

<%
' continue do whatever
%>

Edited 2 Years Ago by Daemon_CC: improvement

Also, what happens when two or more users have the same first initial and same first 4 letters of the last name?

example:

  • Michael Richardson
  • Matthew Richards

Or if 2 or more people have the exact same names?

  • John Smith
  • John Smith

It is probably better to let the user choose his/her username. Check if the username is available. If not, prompt the user for a different username.

Edited 2 Years Ago by cgeier

And what if there is a middlename. What if the name field is empty. What if th last name consists of multiple words. Etc.

When we suggest solutions here, are we supposed to garantee that they will work under absolutely all circumstances, or is it not more appropriate to solve a simple use case that is clear and cut.

Edited 2 Years Ago by PerplexedB

Depends on the problem statement. It's also good to think of things that might occur in the real world as someday you'll have to deal with it.

This question has already been answered. Start a new discussion instead.