Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every one

I'm beginner in asp.net(C#) and my question is that i need to add text like "ABC" to the beginning of more than one text in multiline textbox, for example i have this :
aaaa
bbbb
cccc
ddd
mmmm
and i wont it to be like this :
ABCaaaa
ABCbbbb
ABCcccc
ABCddd
ABCmmmm
by pressing on a button which it's value is "add ABC",
i had already searched in Google but with no result unfortunately.
i will be thankful for any help.

Best Regards
Ahmed
Posted

Here are 2 ways to accomplish this: Method 1 is the safer option

1.

C#
protected void Button1_Click(object sender, EventArgs e)
{
            string a = TextBox1.Text;

            string[] b = a.Split(new string[] {  System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            StringBuilder sb = new StringBuilder();
            foreach (string ss in b)
            {
                sb.Append("ABC");
                sb.Append(ss);
                sb.Append(System.Environment.NewLine);
            }


            TextBox1.Text = sb.ToString();
}


2.

C#
protected void Button1_Click(object sender, EventArgs e)
{
            string a = TextBox1.Text;

            string[] b = a.Split(new string[] {  System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            TextBox1.Text = string.Empty;
            foreach (string ss in b)
            {
                TextBox1.Text += ("ABC" + ss + System.Environment.NewLine);
                
            }


            
}
 
Share this answer
 
v4
Comments
Ahmed k dema 8-Dec-11 2:26am    
thank you very much sir,I'm really appreciate that.

Best regards
Ahmed
You can try simple like below

C#
string prevdata = "";
        private void button1_Click(object sender, EventArgs e)
        {
            prevdata = txtmulti.Text;
            txtmulti.Text = "";
            txtmulti.AppendText(textBox2.Text);
            txtmulti.AppendText(prevdata);
        }


visit
http://developers.eventsitsolution.com/[^]

for more info

VB
Regards
Amar
 
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