让我们说这是文件中的文本。它将删除冒号,并将每个单词放入数组中的自己的字符串中。例如:
exampleArray[0] = 'hello'
exampleArray[1] = 'my'
exampleArray[2] = 'name'
exampleArray[3] = 'is'
exampleArray[4] = 'lavi'
这是我的密码:
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Text Files|*.txt";
DialogResult result = ofd.ShowDialog();
if(result == DialogResult.OK)
{
StreamReader textfile = new StreamReader(ofd.FileName);
string s = textfile.ReadToEnd();
string[] split = s.Split(':', '\n');
foreach (string word in split)
textBox1.Text = word[0].ToString();
//listBox1.Items.Add(word);
ofd.Dispose();
}
谢谢!
编辑:,我想说的是如何使每个单词都存储在数组中,以便以后可以使用1、2等进行访问?如果拆分是自动的,我如何访问每个单词?
发布于 2012-05-16 13:08:02
只需使用这个:
foreach (string word in split) textBox1.Text = word.ToString();
发布于 2012-05-16 13:05:57
对于“我想说的是如何使每个单词都存储在一个数组中,以便以后可以使用1、2等进行访问?如果拆分是自动的,我如何访问每个单词?”
变量myWord =Split0.n
发布于 2018-05-30 21:58:16
string[] exampleArray = str.Split(":");
https://stackoverflow.com/questions/10626455
复制