1
Weekly challenge / Re: Challenge 1 - Text scrambler
« Last post by ca0s on Today at 09:03:12 PM »Nice but there is the problem of some words not being changed.I didn't even think about just reverse the word leaving first and last letters in place, lol.
My code is written in Visual Basic 6 and is 17 lines long, excluding white space and comments.Code: [Select]Dim strWords() As String
Dim strFirst As String, strLast As String, strMix As String, strNew As String
Dim I As Integer, P As Integer
' Split each word of the input into an array
strWords() = Split(Text1.Text, " ")
' Loop through array
For I = 0 To UBound(strWords())
' This IF removes the possible error for 'Len(strMix) - 1' as a single letter word would
' cause a problem.
If Len(strWords(I)) > 1 Then
strFirst = Left$(strWords(I), 1) ' Grab first letter
strLast = Right$(strWords(I), 1) ' Grab last letter
strMix = strWords(I)
strMix = Right$(strMix, Len(strMix) - 1) ' Remove the first letter
strMix = Left$(strMix, Len(strMix) - 1) ' Remove the last letter
' Reverse what's left *wink*
strMix = StrReverse(strMix)
' Combine first letter, reversed string and last letter together
strNew = strFirst + strMix + strLast
' Put the new word into the array
strWords(I) = strNew
End If
Next
' Output
Debug.Print Join(strWords())
And the output is:Code: [Select]Anidroccg to a rehcraeser at Cgdirbmae Uytisrevin, it d'nseot mettar in waht oedrr the lrettes in a wrod aer, the olny inatropmt tnihg is taht the fsrit and lsat letter be at the rhgit pecal. The rset can be a tatol mses and you can slitl raed it wuohtit pmelbor. Tihs is bsuacee the hamun mnid deos not raed erevy letter by ilestf but the wrod as a weloh.
Execution time in seconds: 0
Anidroccg to a rehcraeser at Cgdirbmae Uytisrevin, it d'nseot mettar in waht oedrr the lrettes in a wrod aer, the olny inatropmt tnihg is taht the fsrit and lsat letter be at the rhgit pecal. The rset can be a tatol mses and you can slitl raed it wuohtit pmelbor. Tihs is bsuacee the hamun mnid deos not raed erevy letter by ilestf but the wrod as a weloh.
benchmark = 0 milliseconds.
(00.00 seconds).
Awesome, ain't it?The only thing I missed out was the punctuation checking
![]()

Recent Posts
The only thing I missed out was the punctuation checking



