对于每个“&"列表框 [英] For Each "&" Listbox

查看:72
本文介绍了对于每个“&"列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿家伙

如果我有一个文本框,其中包含大量文本,我可以对

If  I have a text box that contains a load of text what code could I use to

1使用什么代码.当文本包含&"

1. Split text when the text contains "&"

2时拆分文本.添加到列表框

2. Add to a list box

 

例如

TextBox1.Text ="name = bob& age = 23& sex = male";

TextBox1.Text = "name=bob&age=23&sex=male";

列表框1:

name = bob

name=bob

age = 23

sex = male

sex=male

 

谢谢

 

更新:感谢您的回答,这是我的最终代码.如果其他人有兴趣

UPDATE: Thanks for answer, this is my final code  if anyone else is interested

[CODE]

                                    字符串文本= richTextBox1.Text;
           string [] words = text.Split(''&'');

                                     foreach(字符串中的单词)
          {
                        listBox1.Items.Add(word);
           }

            string text = richTextBox1.Text;
            string[] words = text.Split(''&'');

            foreach (string word in words)
            {
                listBox1.Items.Add(word);
            }

[/CODE]

推荐答案

好,您回答了自己的问题.字符串类具有split方法.您可以将其转换为字符串数组,每个字符串包含所需的值.您甚至可以使该数组成为列表框的数据源,这将使它按需要显示.

Well, you answered your own question.  The string class has a split method.  You can turn this into an array of strings, each containing the values you want.  You can even make that array the data source of the listbox, which will cause it to show as you want.


这篇关于对于每个“&"列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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