Click here to Skip to main content
15,867,686 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
Posted
Updated 31-Mar-22 10:20am
v2
Comments
[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:
C#
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
 
v2
hi....

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
arry[1]=ankit
arry[2]=sahoo

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

a.a.sahoo


-Enjoy Coding
 
Share this answer
 
try following code snippet :

C#
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) + ".";
    }
    else
    {
        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