AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fun scripting: Word Jumbler

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
TheGood



Joined: 30 Jul 2007
Posts: 516

PostPosted: Sat Feb 21, 2009 2:00 am    Post subject: Fun scripting: Word Jumbler Reply with quote

I wrote this while on a break from studying.
It basically jumbles the letters of each word but leaving the first and last letters untouched.
I'm sure you guys received emails with this (it's quite old):
Quote:
The phaonmneal pweor of the hmuan mnid, aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoatnt tihng is taht the frist and lsat ltteer be in the rghit pclae. The rset can be a taotl mses and you can sitll raed it wouthit a porbelm.

Well, all my script does is that it transforms any text currently selected into a jumbled version and places it on the clipboard. Default hotkey is Win+z.

Code:
#z::
   
   ;Clear clipboard
   Clipboard =
   
   ;Copy selection and wait for it to get to the clipboard
   SendInput ^c
   ClipWait
   
   s := Clipboard
   
   ;Jumble words
   i := 1
   Loop {
      i := RegExMatch(s,"P)[a-zA-Z]{4,}",l,i)
      If Not i
         Break
      Else Jumble(s,i,l)
      i += l
   }
   
   ;Put back in clipboard
   ClipBoard := s
   
Return

Jumble(ByRef s, pos, len) {
   
   ;Extract the middle letters
   l := len - 2
   t := SubStr(s, pos + 1, l)
   
   ;Jumble the letters
   Loop {
      
      ;Get random number
      Loop {
         Random, r, 1, l
         i := NumGet(t, r - 1, "UChar")
         If i
            Break
      }
      
      ;Put the chosen letter in the next pos
      NumPut(i, s, pos + A_Index - 1, "UChar")
      NumPut(0, t, r - 1, "UChar")
      
      If (A_Index = l)
         Break
   }
}
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group