C#Web应用程序问题

问题描述:

我想将任何文本框的字符串ie = 1,2,45,178移动到此格式的列表框中1 2 45 178逐项输出......在C#Web应用程序中



请建议一些相同的编码

I want to move string of any textbox ie = 1,2,45,178 to listbox in this format 1 2 45 178 itemwise output......in C# Web application

Please suggest some coding for the same

编译错误消息:CS0103:当前上下文中不存在名称'words'>


来源错误:





第111行:

第112行:string [] splitedStr = text.Split(delimeterchars);

第113行:foreach(字符串str in words)

第114行:{

第115行:ListBox5.Items.Add(str.ToString(),str.ToString());





第113行中的错误请更正它........
Compiler Error Message: CS0103: The name 'words' does not exist in the current context

Source Error:


Line 111:
Line 112: string[] splitedStr = text.Split(delimeterchars);
Line 113: foreach (string str in words)
Line 114: {
Line 115: ListBox5.Items.Add(str.ToString(), str.ToString());


Error in Line 113 please correct it........


您可以使用 String.Split()方法。





例如:



You can use String.Split() method.


For example:

// your case delimiter will be ','

     char[] delimiterChars = { ',' };

      string text = txtbox1.Text;// txtbox1 is treated your textbox

      string[] splitedStr = text.Split(delimiterChars);

      foreach (string str in splitedStr )
      {
          lstbox1.Items.Add(str.ToString(),str.ToString());  //lstbox1 as your listbox
      }


你不能使用textbox.text.split(',')吗?
Can't you use textbox.text.split(',') ?