Click here to Skip to main content
15,666,974 members
Please Sign up or sign in to vote.
1.15/5 (5 votes)
See more:
I have a written a full name in one textbox. I want to display the short name in another textbox when clicking on Submit button.
For example: alia ankit sahoo
The result should be a.a.sahoo
Updated 31-Mar-22 10:20am
[no name] 19-Oct-12 7:18am    
Okay and? What would the problem be?
fjdiewornncalwe 19-Oct-12 9:56am    
Please use full words, not text speak. Many of us old codgers really dislike this young guy talk... :)

Assuming that space is the only delimiting character, you could try:
string s = "alia ankit sahoo";
string[] words = s.Split(' ');
for (int i = 0; i < words.Length - 1; i++)
    words[i] = words[i].Substring(0, 1);
s = string.Join(".", words);
Share this answer
1) Copy full name into a string variable.
2) Convert that string variable to Character Array using .ToCharArray().
3) Use some logic to get desired result from that character array.
Share this answer

you can do this by using split and then substring

1>first u can spilt full name string by space (' ') so u get tree value in your exapmle

string fullname=alia ankit sahoo;

string[]arry= fullname.split(' ');

now you get tree arry[0]=alia

now you get first caracter of arry[0] and arry[1] and full arry[2]

so you get your resulu

string result=arry[0].Substring(0,1)+"."+arry[1].Substring(0,1)+"."+arry[2];

in result string you get your result string


-Enjoy Coding
Share this answer
try following code snippet :

String[] strShortName = TextBox1.Text.Split(' ');

string str1 = "";
for (Int16 i = 0; i < strShortName.Length; i++)
    if (i < 2)
        str1 = str1 + strShortName[i].ToString().Substring(0,1) + ".";
        str1 = str1 + strShortName[i];
TextBox2.Text = str1;
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900