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 

StringMod() String Manipulation - Enhanced by PhiLho / Titan
Goto page Previous  1, 2, 3, 4, 5, 6
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Tue Jul 28, 2009 4:11 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
ghee22



Joined: 04 Jul 2009
Posts: 36

PostPosted: Sat Nov 07, 2009 6:22 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
MasterFocus



Joined: 08 Apr 2009
Posts: 3035
Location: Rio de Janeiro - RJ - Brasil

PostPosted: Sat Nov 07, 2009 7:08 pm    Post subject: Reply with quote

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

Antonio França
My stuff: Google Profile
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
Goto page Previous  1, 2, 3, 4, 5, 6
Page 6 of 6

 
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