AutoHotkey Community

It is currently May 26th, 2012, 9:19 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 78 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6
Author Message
 Post subject:
PostPosted: July 28th, 2009, 5:11 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Oh! It is lost in my pile of backup DVD's, I guess.

You may try this version which also uses my Words.DB : Script for Anagrams, Word manipulation, Scrabble posted by peterm

The links seems to be broken on that Topic and you may follow the following instead.
http://www.autohotkey.net/~peterm/My_Anagram-V6j.ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2009, 7:22 pm 
Offline

Joined: July 4th, 2009, 6:53 pm
Posts: 36
Titan wrote:
Following a recent discussion I remembered this thread and how regular expressions can be used to simplify most things. Here's a new version with comments:
Code:
StringMod(string, method, param1 = "", param2 = "") {
   If method = Only ; remove all characters not in param1 from string:
      new := RegExReplace(string, "i)[^" . param1 . "]")
   Else If method = Omit ; remove characters in param1 from string:
      new := RegExReplace(string, "i)[" . param1 . "]")
   Else If method = Flip ; flip string backwards:
      Loop, % length := StrLen(string) ; loop for the length of the string
         new .= SubStr(string, length - A_Index, 1) ; get character from the end going backwards
   Else If method = Replace ; replace param1 with param2
      new := RegExReplace(string, "i)" . param1, param2)
   Else If RegExMatch(method, "Rot(?:ate)?(\d+)", rotN) ; for Rot13 and Rot47:
   {
      Loop, Parse, string ; for each character in the string:
         new .= Chr((chr := Asc(A_LoopField)) + rotN1) - 94 * (chr > 126)) ; apply rotation transformation
            ; this increases the ASCII value of the character by the specified rotation amount
            ; if the value exceeds 126 (highest character) subtract by 94 (character range)
   }
   Else If method = Scramble ; rearrange characters in random order
   {
      new := RegExReplace(string, "(.)", "$1÷") ; delimit each character with '÷'
      ; this high-ASCII character is unlikely to exist in string, if it does it will be removed
      Sort, new, Random Z D÷ ; randomly sort
      new := RegExReplace(new, "÷") ; remove delimiter
   }
   Else If method = Bloat ; pad each character with param1 and param2:
      new := RegExReplace(string, "(.)", param1 . "$1" . param2)
   Else If method = Pattern ; return the number of times each character appears in the string:
   {
      unique := RegExReplace(string, "(.)", "$1÷") ; delimit each character with '÷' (like in 'Scramble')
      Sort, unique, U Z D÷ ; remove duplicates
      unique := RegExReplace(unique, "÷") ; remove delimiter
      Loop, Parse, unique ; for each unique character in the string:
      {
         StringReplace, string, string, %A_LoopField%, , UseErrorLevel ; get the number of replacements
         new .= A_LoopField . ErrorLevel ; store this alongside the character itself
      }
   }
   Return, new ; return the modified string
}
Untested but I'm sure it works.


Hello Titan, the latest AHK version (1.0.48.05) gives this error upon compiling:
Code:
StringMod.ahk (14) : ==> Missing "("
     Specifically: )
>Exit code: 2    Time: 0.221


Anyone have a fix?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2009, 8:08 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
ghee22 wrote:
Code:
StringMod.ahk (14) : ==> Missing "("

Line 14 is:
Code:
new .= Chr((chr := Asc(A_LoopField)) + rotN1) - 94 * (chr > 126))

Quote:
new .= Chr((...(...))...)...(...))

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 78 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google Feedfetcher and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group