从TextBox获取数组输入 [英] Taking Array input from a TextBox
本文介绍了从TextBox获取数组输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚才有一个问题。我想让用户在逗号分隔的TextBox中输入一些字符/数字,然后以一种方式读取它,以便用逗号分隔的TextBox中的每个元素都是一个数组中的单独元素想要输入那些字符/数字。
例如:输入:12,好,5
数组中的元素:{12,good,5}; < br $> b $ b
我希望每个人都能理解我的问题,并且能够帮助我。
谢谢。
解决方案
object [] array = textBox1.Text.Split(' ,');
简单:
string s = 12,好,5\" 跨度>;
string [] parts = s.Split(' ,');
如果您还需要删除空格:
< span class =code-keyword> string s = 12,good,5;
string [] parts = s.Split(' ,')。选择(p = > p.Trim())。ToArray();
I just had a question. I want to let the user enter a number of characters/numbers in a TextBox separated by commas and then the code to read it in a way so that each element in the TextBox separated by the comma is a separate element in an array into which I want to input those characters/numbers.
For example: Input: 12, good, 5
Elements in the array:{12, "good", 5};
I hope everyone understood my question and will be able to help me.
Thanks.
解决方案
object[] array = textBox1.Text.Split(',');
Easy:
string s = "12,good,5"; string[] parts = s.Split(',');
If you also need to remove spaces:
string s = "12, good, 5"; string[] parts = s.Split(',').Select(p => p.Trim()).ToArray();
这篇关于从TextBox获取数组输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文