C#文本框多行 [英] c# textbox multi line

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

问题描述

我没有在组合框中获得价值的文本框中

  List< string>列表= cmcom.System(textBox1.Text);
              nbsp; bsp    int i = 0;
              nbsp; bsp    foreach(列表中的字符串s)
              nbsp; bsp    {
              nbsp; bsp       comboBox1.Items.Insert(i ++,s);
              nbsp; bsp       comboBox1.SelectedIndex = 0;
              nbsp; bsp       textBox4.SelectedText.Insert(i ++,s);
              nbsp; bsp    }


Support@Mytechnet.me

解决方案

您的问题很难理解.  但是,文本框中的所有文本都是单个字符串.  如果要按行将其拆分,则需要了解该文本将包含"\ r \ n"它们是ascii回车符和换行符.  

有一个常量 Environment.NewLine ,您可以使用它可靠地对其进行处理.

下面是一些代码段,展示了一种将其分解为单独的字符串的方法:

             字符串 > [] temparr  =  inputStr.Replace(环境 .NewLine,"|" ; ).Split("|" .ToCharArray());

String.Split()方法很方便,但是它希望您希望在单个字符上换行.因此,您可以替换"\ r \ n"并使用单个字符(在上面的示例中为竖线),然后使用split进行分隔.


i am not gettting value in textbox whereelse i can get in combobox

 List<string> list = cmcom.System(textBox1.Text);
                            int i = 0;
                            foreach (string s in list)
                            {
                                comboBox1.Items.Insert(i++, s);
                                comboBox1.SelectedIndex = 0;
                                textBox4.SelectedText.Insert(i++, s);
                            }


Support@Mytechnet.me

解决方案

Your question is hard to understand.  However, all of the text in a textbox is a single string.  If you want to break it up by lines, you need to understand that the text will contain "\r\n" which are ascii carriage return and linefeeds.  

There is a constant Environment.NewLine that you can use to deal with this reliably. 

Here's a little code snippet to show one way you could break it up into separate strings:

            string inputStr = textBox1.Text;

            string[] temparr = inputStr.Replace(Environment.NewLine, "|").Split("|".ToCharArray());

The String.Split() method is handy, but it expects that you would want to break lines on a single character. So, you can replace the "\r\n" with a single character (vertical bar in the above example), then use split to separate.


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

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