![]() |
|
|||||||
| VB.NET General Discussion VB.NET general discussion area |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hello all,
I'm not the best when it comes to this, but i've been banging my head for days and i think its time i try to ask some of the very talented ppl i see on this site a quick question. I stumbled across this post from about 2 months ago... Basic Word Jumber What that post is about is almost exactly what i need...except i dont want the characters in the individual words to be changed, i just need the whole words moved around. For example a text file/box that contains this "Jim Tire Tall2 G'night" would be "jumbled" or rearanged randomly to "Tall2 Jim G'night Tire". So far i have this code done, but it only gives me one word at a time, not all the words all at once. Code:
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
Dim MyArray() As String = Split(testtxtbox1.Text, " ")
Dim I As Integer
Dim Index1 As Integer
Dim Index2 As Integer
Dim Temp As String
For I = 1 To 20
Index1 = Int(Rnd() * 10)
Index2 = Int(Rnd() * 10)
While Index1 = Index2
Index2 = Int(Rnd() * 10)
End While
Temp = MyArray(Index1)
MyArray(Index1) = MyArray(Index2)
MyArray(Index2) = Temp
Next I
testtxtbox2.Text = Temp
End Sub
Matt |
|
||||
|
Same concept, almost same code:
Code:
Private r As New Random
Private Function RandomizeWords(ByVal text As String) As String
Dim words As New List(Of String)(text.Split(" "c))
Dim newwords As New List(Of String)
For Each word As String In words
newwords.Insert(r.Next(0, newwords.Count + 1), word)
Next
Return String.Join(" ", newwords.ToArray)
End Function
Quote:
__________________
See this thread about how to use forum markup codes for code blocks etc (present the problem/post properly )Some useful links: Learning videoes, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ DR. WEIR: Download it to a non-networked, firewalled computer. TECHNICIAN: Yes, ma'am. |
|
|||
|
Quote:
Thanks John! Im stuck agian tho, here are the basics on how i'm trying to implement this code. User opens a .txt file and the contents are sent to global variable "content1". Next the user enters in how many randomized words he wants in textbox "totalwords". All the above works with no errors, from here is where i need your help. Once a numerical number is entered the user clicks "button12" and that button is to run that code you gave me, thus jumbling whats inside variable "content1" and taking out however many words was entered into the variable "totalwords". Once the code you gave me has jumbled up enough words to satisfy the number defined in "totalwords", the jumbled words are to be sent to a global variable named "scrambled1". And thats it! The code you gave me works perfect, except for some reason i just cant link the "button12" to activate it and put the radomized words (matching the "totalwords" variable) into the global variable "scrambled1". Thanks! |
|
|||
|
Hey there.
I want to hear if there is a way to do this so that it dosen't just mix up the word (ex. word to be mixed: hejlol end up like llojeh). I want to know if its possible to like only make words with 3 letters or 4 and so on. Like word to be mixed: helloa ends up like lol or hello so that it makes many different words in different lenght's? Hope you know what i mean :-) Kind Regards OutRager- |
|
|||
|
Quote:
I've figured out the rest to my last question, but i'm still bangin my head on trying to "pick" x amount of words out of the "words" variable. Any suggestions? Thanks! Matt |
|
||||
|
matty, learn how to use a For-Next loop.
__________________
See this thread about how to use forum markup codes for code blocks etc (present the problem/post properly )Some useful links: Learning videoes, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ DR. WEIR: Download it to a non-networked, firewalled computer. TECHNICIAN: Yes, ma'am. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|