 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Thu Sep 14, 2006 10:42 am Post subject: |
|
|
| 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 . I am too tired working with Cheetah2.dll ..
| 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! . I should return back to my habit.
Regards,  _________________ URLGet - Internet Explorer based Downloader |
|
| Back to top |
|
 |
polyethene
Joined: 11 Aug 2004 Posts: 5248 Location: UK
|
Posted: Thu Sep 14, 2006 10:55 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Thu Sep 14, 2006 11:00 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
polyethene
Joined: 11 Aug 2004 Posts: 5248 Location: UK
|
Posted: Thu Dec 28, 2006 10:58 pm Post subject: |
|
|
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. _________________ GitHub Scripts IronAHK Contact by email not private message. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Thu Dec 28, 2006 11:01 pm Post subject: |
|
|
As long as the parameters are correctly escaped, if needed... _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
polyethene
Joined: 11 Aug 2004 Posts: 5248 Location: UK
|
Posted: Thu Dec 28, 2006 11:03 pm Post subject: |
|
|
| PhiLho wrote: | | As long as the parameters are correctly escaped, if needed... | Sorry did I miss something? _________________ GitHub Scripts IronAHK Contact by email not private message. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Fri Dec 29, 2006 9:20 am Post subject: |
|
|
Examples of not working parameters:
StringMod(str, "Omit", ".-,;")
StringMod(str, "Replace", "*", "o")
etc. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Fri Dec 29, 2006 9:59 am Post subject: |
|
|
Nice work Titan .
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 |
|
| Back to top |
|
 |
polyethene
Joined: 11 Aug 2004 Posts: 5248 Location: UK
|
Posted: Fri Dec 29, 2006 2:34 pm Post subject: |
|
|
| 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. _________________ GitHub Scripts IronAHK Contact by email not private message. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Fri Dec 29, 2006 2:43 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Sat Apr 28, 2007 1:37 pm Post subject: |
|
|
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,  |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Sat Apr 28, 2007 2:55 pm Post subject: |
|
|
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% |
|
|
| Back to top |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 162
|
Posted: Mon Jul 27, 2009 10:06 pm Post subject: |
|
|
Sorry to awaken this old thread, SKAN do you still have your anagrammer.zip file? That's exactly what i'm trying to make . |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Tue Jul 28, 2009 5:25 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 162
|
Posted: Tue Jul 28, 2009 2:11 pm Post subject: |
|
|
| Hmm, I don't see the anagram script, only the code for the function |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|