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];
}
}
}
}
}
答案 0 :(得分:1)
如果您想拆分文本,请使用String.Split
为您提供一系列字词:
string[] words = textBox1.Text.Split(" ");
答案 1 :(得分:0)
这完全符合“问题”中概述的内容,并假设输入中可能包含单个“单词”。如“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;