Vb.net 更改给定文本框中句子的顺序

Vb.net 更改给定文本框中句子的顺序,vb.net,visual-studio,Vb.net,Visual Studio,我考虑过决心,但我不知道怎么做 例如,我在文本框的每一行都有一些句子 Sentence 1 Sentence 2 Sentence 3 我希望输出“混合/随机”如下: Sentence 3 Sentence 1 Sentence 2 有什么想法吗?我对编程不太在行。您可以使用Linq的扩展方法来完成这项任务 'Setup Dim txtYourTextBox As New TextBox txtYourTextBox.Text = "Sentence 1" &

我考虑过决心,但我不知道怎么做

例如,我在文本框的每一行都有一些句子

Sentence 1
Sentence 2
Sentence 3
我希望输出“混合/随机”如下:

Sentence 3
Sentence 1
Sentence 2
有什么想法吗?我对编程不太在行。

您可以使用Linq的扩展方法来完成这项任务

    'Setup
    Dim txtYourTextBox As New TextBox
    txtYourTextBox.Text = "Sentence 1" & ControlChars.NewLine & "Sentence 2" & ControlChars.NewLine & "Sentence 3"

    'Creates random numbers.
    Dim rnd As New System.Random()

    'Get the list of sentences randomized.
    Dim lstRandomizedSentences As List(Of String) = txtYourTextBox.Text.Split(ControlChars.NewLine).OrderBy(Function() rnd.Next).ToList()

    'Clear the textbox before repopulating with randomized sentences.
    txtYourTextBox.Text = String.Empty

    'Loop through all of your randomized sentences to populate the textbox.
    For Each strSentence In lstRandomizedSentences

        '.Trim() so extra line breaks aren't added.
        txtYourTextBox.Text += strSentence.Trim() & ControlChars.NewLine

    Next

是的,看看字符串类;也许是弦,分开。然后是随机类。尝试一些代码,如果你有一个特定的问题,张贴你的代码和问题。