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
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