我尝试在 Form1 中这样做:
private void BtnScrambleText_Click(object sender, EventArgs e)
{
textBox1.Enabled = false;
BtnScrambleText.Enabled = false;
StringBuilder sb = new StringBuilder();
var words = textBox1.Text.Split(new char[] { ' ' });
foreach (var w in words)
{
if (w == " ")
{
sb.Append(w);
continue;
}
ScrambleTextBoxText scrmbltb = new ScrambleTextBoxText(w);
scrmbltb.GetText();
sb.Append(scrmbltb.scrambledWord);
textBox2.AppendText(sb.ToString());
}
}
我的新课程是 ScrambleTextBoxText,我只是从 textBox1 中得到一个单词,随机地对其进行加扰,然后将加扰的单词添加回 textBox2
但是在 textBox2 中,我看到一个长字符串中的所有单词,例如:
dannyhihellobyethis
单词之间根本没有空格。我需要将它添加到 textBox2 中,并使用它在 textBox1 中的确切空格。
如果在 textBox1 中是例如:
丹尼你好嗨是的二四
moses daniel yellow
所以在 textBox2 它应该是同一行:
丹尼你好嗨是的二四
moses daniel yellow
有相同的空间,两行向下和一切。
两个问题:
textBox2 中没有空格
它将我在 textBox1 中输入的任何单词添加到 textBox2 但它应该只添加从我的新类返回的单词:scrmbltb.scrambledWord
例如,如果我在 textBox1 中输入:hi daniel
所以在 textBox2 中应该是 : daniel 没有这个词 : hi
或者如果在 textBox1 中是:daniel hi hello 那么在 textBox2 中它将是:daniel hello