Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alphabets Shuffle in a String?

Status
Not open for further replies.

nomi2000

ISP
Feb 15, 2001
676
CA
Hi
I am working on shuffling alphaets in a string so its covnerted in to drunk man word like
"explorer" converted to "eplorxre"
Regards
Nouman

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim oFile As System.IO.File
Dim oWrite As System.IO.StreamWriter
Dim oRead As System.IO.StreamReader
Dim arrVariant(80) As String
Dim processLine As String
Dim LineToWrite As String
Try
oRead = oFile.OpenText("C:\Test.txt")
oWrite = New System.IO.StreamWriter("C:\TestNew.txt")
Do Until oRead.Peek = -1
processLine = oRead.ReadLine
arrVariant = Split(processLine, " ")
'ArrayShuffle(arrVariant)
WordShuffleInArray(arrVariant)
'Write to another file
LineToWrite = Join(arrVariant)

oWrite.WriteLine(LineToWrite)
Loop
oWrite.Close()
oRead.Close()
Finally

End Try



End Sub
' Shuffle the elements of an array of any type
' (it doesn't work with arrays of objects or UDT)
Sub WordShuffleInArray(ByVal arr As Object)
Dim index As Long
Dim newIndex As Long
Dim firstIndex As Long
'Dim itemCount As Long
Dim tmpValue As Object
Dim Counter As Integer

'firstIndex = LBound(arr)
'itemCount = UBound(arr) - LBound(arr) + 1

For index = LBound(arr) To UBound(arr)

firstIndex = 1
tmpValue = ""
'Now swapping the aplhabets in arr(Index)
For Counter = 1 To Len(arr(index))
newIndex = firstIndex + Int(Rnd() * Counter)
tmpValue += Mid(arr(newIndex), newIndex, 1)
Next
arr(index) = tmpValue

Next
End Sub

Nouman Zaheer
Software Engineer
MSR
 
er... whats the problem you're having?

split returns a string array (string()) which you can then process via a for each command. other than knowing the problem your having I would find it difficult to help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top