Write in new line in rich text box. with vb

后端 未结 4 1743
[愿得一人]
[愿得一人] 2021-01-23 21:29

Hi guys i want to know how to write every word in a phrase in a new line in a richtextbox lets say the phrase is this \"Returns a string array that contains the substrings in t

相关标签:
4条回答
  • 2021-01-23 22:11

    You can use the vbCrLf constant:

        For Each s As String In split
            If s.Trim() <> "" Then
                RichTextBox1.Text = (s) + vbCrLf
            End If
        Next s
    
    0 讨论(0)
  • 2021-01-23 22:12

    I like to use vbCrLf constant:

    RichTextBox1.Text = TextBox1.Text.Replace(" ", vbCrLf).Replace(vbTab, vbCrLf)
    
    0 讨论(0)
  • 2021-01-23 22:13
    Dim words As String = TextBox1.Text
    words.Replace(" ", ControlChars.Lf)
    RichTextBox1.Text = words
    

    You just need to replace " " by ControlChars.Lf aka New Line Character

    0 讨论(0)
  • 2021-01-23 22:15

    Your code is fine except for one thing. You are setting the RichTextBox to the string everytime, so it keeps overwriting. You need to concatenate...

    Dim words As String = TextBox1.Text
    Dim split As String() = words.Split(New [Char]() {" "c, CChar(vbTab)})
    
    For Each s As String In split
        If s.Trim() <> "" Then
            RichTextBox1.Text &= (s)
        End If
    Next s
    

    Note that addition of the "&" on the line that writes to the RTB.

    0 讨论(0)
提交回复
热议问题