如何在多行文本框的开头添加文本 [英] how to add text in the beginning of multiline textbox

查看:95
本文介绍了如何在多行文本框的开头添加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我是asp.net(C#)的初学者,我的问题是我需要在多行文本框中的多个文本的开头添加"ABC"之类的文本,例如,我有这样的内容:
aaaa
bbbb
cccc
ddd
mmmm
我不会像这样:
ABCaaaa
ABCbbbb
ABCcccc
ABCddd
ABCmmmm
通过按下其值为添加ABC"的按钮,
我已经在Google中搜索过,但不幸的是没有结果.
我会很感激您的帮助.

最好的问候
Ahmed

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

推荐答案

有两种方法可以做到这一点:方法1是更安全的选择

1.

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

1.

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.



2.

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);
                
            }


            
}


您可以像下面这样简单尝试

You can try simple like below

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



访问
http://developers.eventsitsolution.com/ [ ^ ]

了解更多信息



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

for more info

Regards
Amar


这篇关于如何在多行文本框的开头添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆