AutoHotkey Community

It is currently May 25th, 2012, 3:00 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 78 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject:
PostPosted: September 14th, 2006, 11:42 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
PhiLho wrote:
That's because on a long string, the StringSplit will have to find and allocate all the variables, even if only the first is requested. While the Loop Parse stops as soon as it reached its goal, and drops intermediary results.


I agree .. :) This was the exact thing I wanted to tell :shock: . I am too tired working with Cheetah2.dll .. :D

PhiLho wrote:
Goyyah, why do you hate so much space? I like to put a space after commas and around = or :=, I find it easier on the eye, code breathes... :-)


Yes it looks very bad in BBCode .. however "not-so-bad" in my editor .. I always use space after a comma.. I do not know why I changed it! :shock: . I should return back to my habit.

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2006, 11:55 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
PhiLho wrote:
Conceptually, I prefer Goyyah & toralf's way than your, Titan.
I thought it was all about code size. Personally I would use toralf's method because it's the fastest.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 14th, 2006, 12:00 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
I am using toralf's code already ..

PhiLho wrote:
Conceptually, I prefer Goyyah & toralf's way than your, Titan.


but, PhiLho must have meant Loop,Parse Vs StringSplit method.

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2006, 11:58 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
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.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2006, 12:01 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
As long as the parameters are correctly escaped, if needed...

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2006, 12:03 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
PhiLho wrote:
As long as the parameters are correctly escaped, if needed...
Sorry did I miss something?

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2006, 10:20 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Examples of not working parameters:
StringMod(str, "Omit", ".-,;")
StringMod(str, "Replace", "*", "o")
etc.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2006, 10:59 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Nice work Titan :D.
I am yet to test it, but I know it will work fine.
FYI: I have linked that post in the title post.

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2006, 3:34 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
PhiLho wrote:
As long as the parameters are correctly escaped, if needed... StringMod(str, "Omit", ".-,;")
Oh yeah, param1 := RegExReplace(param1, "([\[\\\^\$\.\|\?\*\+\(\)])", "\$1") should be enough right?

Skan wrote:
I have linked that post in the title post.
The link to StringMod.ahk on my site still works btw.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2006, 3:43 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Titan wrote:
The link to StringMod.ahk on my site still works btw.


Oh! So the old version is not available! :(

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2007, 2:37 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Dear Titan, :)

Thanks for the RegEx version. Iam using Scramble in one of my scripts.

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


Regards, :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2007, 3:55 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
It looks slightly safer to use a non-printable ANSI character for delimiter:
Code:
string = qwertyu iop[
new := RegExReplace(string, "(.)", "$1" Chr(1))
Sort new, % "Random Z D" . Chr(1)
StringReplace new, new, % Chr(1),,All
MsgBox %new%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2009, 11:06 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
Sorry to awaken this old thread, SKAN do you still have your anagrammer.zip file? That's exactly what i'm trying to make :).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 28th, 2009, 6:25 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
silkcom wrote:
Sorry to awaken this old thread, SKAN do you still have your anagrammer.zip file?


You may download a copy of words.db ( 2.47 MiB ) which is the datafile for the anagram script posted in this topic.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 28th, 2009, 3:11 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
Hmm, I don't see the anagram script, only the code for the function


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  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, oldbrother 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