I wanna make some kind of funny application where I write in a textbox "Hay man" then press a button the text change to "man Hay" and so on even with increasing words on the textbox
So I need to know how to:

1) make VB see that this is a "space" so it can differentiate between words
2) How to make it ignore symbols like in sentence "Hay, how are you?" which suppose to be written as after pressing the button "you are how hay"

Thanks for reading!

-Sorry I am still a noob

Just an idea to start.....this will deal with ur first condition of spaces

Dim s As String = "This is my Dog"
Dim words As String() = s.Split(" "c)
Array.Reverse(words)
s = String.Join(" "c, words)

Dim s As String = "This is my Dog"
Dim words As String() = s.Split(" "c)
Array.Reverse(words)
s = String.Join(" "c, words)

Oh OuO Thank chu! I will see what I can do now ^u^

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s As String = TextBox1.Text
        Dim words As String() = s.Split(" "c)
        Array.Reverse(words)
        s = String.Join(" "c, words)
        TextBox1.Text = s
    End Sub
End Class

That made it work perfectly but with symbols it consider the symbol a part from the word >w> So I still need the second requirement
And if you don't mind Poojavb, I would like you to tell me how did that thing works:
1) What's the differ between "String" and "String()"
2) What does (String).Split represent ((I tried to read what VB write when my cursor is above it, but I didn't understand))
3) What does the "c" mean
4) Reverse is to reverse the words of course so I don't need that a lot but define "Array"
5) What is the use of "Join" exactly here?

Sorry if this annoy you ^^" I am just a noob who would like to learn more and more .w.

  1. String is a type, that represents a string of Unicode characters. string is an alias for System.String in the .NET Framework.
  2. String() is an array (more strings "together" can make an array of strings).
  3. Spit my white spaces (" "c).
  4. Reverse is a method of String class, that can turn around (in exactly reversed order) - and does not change anything else (you said you want to have written words in reverse order -so this does that - BUT its does not reverse charcters of each string).
  5. Join creates a string from an array. And he defined ("Join(" ", Array) - this means Join what is in array, and make white space between each string)

This is it!

Hop it helps a bit.

btw, here is my version of reversing string:

Dim str As String = "reverse this string"
Dim reverseStr = str.Split(" "C)
.[Select](Function(a, b) New With { _
    Key .WORD = a, _
    Key .INDEX = b _
})
.OrderByDescending(Function(o) o.INDEX)
.[Select](Function(s) s.WORD).ToArray()
.Aggregate(Function(a, b) Convert.ToString(a) & " " & Convert.ToString(b))

Dont be scared, this is just a Linq ("simplifies" things sometimes :) ).

bye

Do visit again in case of any queries or to help others.... :)

Edited 4 Years Ago by poojavb

This article has been dead for over six months. Start a new discussion instead.