How to move the first word to the end of a string in VB.NET

1 Answer

0 votes
Imports System
Imports System.Linq

Module Program

    Function move_first_word_to_end_of_string(s As String) As String
        Dim parts() As String = s.Trim().Split({" "}, StringSplitOptions.RemoveEmptyEntries)

        If parts.Length <= 1 Then
            Return s.Trim()
        End If

        ' Build the result: all words except the first, then the first at the end
        Dim result As String = String.Join(" ", parts.Skip(1)) & " " & parts(0)

        Return result
    End Function

    Sub Main()
        Dim s As String = "Would you like to know more? (Explore and learn)"
        Dim result As String = move_first_word_to_end_of_string(s)

        Console.WriteLine(result)
    End Sub

End Module



' run:
'
' you like to know more? (Explore and learn) Would
'

 



answered Feb 5 by avibootz
...