-1

请帮助我希望程序从文本框 1 中获取文本显示文本框 2 中的所有文本,如果遇到空格停止并在文本框 3 中显示单词,程序会在文本框 2 中显示整个文本,但它确实不适用于文本框 3 帮助

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string[] sent = new string[100];
        string[] word = new string[50];


        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i <= textBox1.Text.Length; i++)
            {
                sent[i] = textBox1.Text;  
                textBox2.Text = sent[i];
                for (int j = 0; j <= textBox1.Text.Length; j++)
                {
                    if (sent[i] == " ")
                        word[j] = sent[i];
                    textBox3.Text = word[j];
                }
            }


        }
    }
}  
4

2 回答 2

1

如果要拆分文本,请使用String.Split给您一个单词数组:

string[] words = textBox1.Text.Split(" ");
于 2013-03-19T18:06:50.507 回答
0

This does exactly what is outlined in the "question" and assumes a singular "word" may be among the input. Such as "dfsgkujhdafkj;hsadfkjsd word sdfkjhsdfkjsdf"

        string originalText = textBox1.Text.Trim();
    textBox2.Text = originalText;
    textBox3.Text = originalText.Contains(" ") ? originalText.Substring(originalText.IndexOf(" "), (originalText.Substring(originalText.IndexOf(" ") + 1).Contains(" ") ? originalText.Substring(originalText.IndexOf(" ") + 1).IndexOf(" ") + 1 : originalText.Length - originalText.IndexOf(" "))) : string.Empty;
于 2013-03-19T18:20:48.913 回答