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  Next
 
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: Sat Mar 04, 2006 12:48 pm    Post subject: Reply with quote

Dear PhiLho Smile ,
I want one more feature (a bit tough for me to accomplish) to be included inside the parsing loop. Can you help me?... Please.

Regards, Smile

Edit: I request you to save your code as .AHK and provide me with a link that will appear in the first post
_________________
URLGet - Internet Explorer based Downloader


Last edited by SKAN on Sun Mar 05, 2006 1:15 pm; edited 3 times in total
Back to top
View user's profile Send private message Send e-mail
polyethene



Joined: 11 Aug 2004
Posts: 5248
Location: UK

PostPosted: Sat Mar 04, 2006 12:52 pm    Post subject: Reply with quote

PhiLho wrote:
Well, Titan's code is short and al, but it doesn't do true Rot13, which acts only on alphabetic characters and replaces them only by alphabetic chars...
Wrong!
I updated the algorithm (see my above post).. sorry for the initial mistake.

@Goyyah, you can upload scripts for free on the AutoHotkey.net file manager.
_________________
GitHubScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sat Mar 04, 2006 1:06 pm    Post subject: Reply with quote

Dear Titan, Smile

you wrote:
you can upload scripts for free on the AutoHotkey.net file manager.


I am aware of that, and have been uploading lot of files. Thanks to you. But I thought you would like to put your version (as .AHK) on your homepage or something, and also you might want to include some note on Version number/Author etc.

Simply put, you modify your code and update your AHK and I dont have to update the download link that shall be on the first post.

Thanks again, Smile
_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
polyethene



Joined: 11 Aug 2004
Posts: 5248
Location: UK

PostPosted: Sat Mar 04, 2006 1:10 pm    Post subject: Reply with quote

I see your logic, clever.. okay, here's the link: http://www.autohotkey.net/~Titan/dl/StringMod.ahk.

I'm reluctant to include this script on my page becuase it's actually your creation and I don't want to steal your due credit Smile If you'd like me to promote this script however, I'd be glad to do so.
_________________
GitHubScriptsIronAHK Contact by email not private message.


Last edited by polyethene on Wed Feb 17, 2010 5:03 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sat Mar 04, 2006 1:30 pm    Post subject: Reply with quote

Dear Titan, Smile
You wrote:
I'm reluctant to include this script on my page becuase it's actually your creation and I don't want to steal your due credit If you'd like me to promote this script however, I'd be glad to do so


Smile , I don't want any credit for this. If PhiLho had not spotted this function (in the original post) and spent his valuable time enhancing, it would have faded away!. StringMod() has been lucky twice, and you have enhanced it again.

Do whatever you want to do with the code but I request you that the function name remains StringMod(). Please!

And I invite you and everybody to promote this function.

Regards, Smile
_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
PhiLho



Joined: 27 Dec 2005
Posts: 6836
Location: France (near Paris)

PostPosted: Sat Mar 04, 2006 3:10 pm    Post subject: Reply with quote

OK, I uploaded the file to AutoHotkey.net.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sat Mar 04, 2006 5:58 pm    Post subject: Reply with quote

Dear PhiLho & Titan, Smile

SCRAMBLED / JUMBLED Words

Code:
String = AUTOHOTKEY
Loop, 33
   Str = % Str Scramble(String) Chr(10)
Msgbox,0, % String,% Str

Scramble(String)
{
Loop, Parse,String
 ReturnString = % ReturnString A_LoopField Chr(10)
Sort,ReturnString,Random
Null:= ""
StringReplace, String, ReturnString, `n, %Null%,All
return String
}


Sample output of above code for word "AUTOHOTKEY"

    OTUYTHOAEK
    KYOAETTOUH
    AETTOYUKHO
    TEYUOTAOHK
    HKTATYEOOU
    OYKATHEOTU
    KETOYTOHUA
    AEHTOOYUTK
    TTOYEKOHUA
    UAOEHKTYTO
    ETTHOOKAUY
    HOTUAYOTEK
    TOTUAOHYKE
    HOKYETTUOA
    OTEHOATKUY
    UOTYHEKOAT
    HAUTTOOYEK
    HOYATEOTKU
    OTKEOAYHUT
    KAOYHEUTOT
    UTHKEOTOYA
    UTHOTKYOEA
    TOYAUHETOK
    TTYAOKEHOU
    ETTUOHYKOA
    EAOUKTTOHY
    KHATYOUOTE
    UOOHAETKYT
    YOHEUOATKT
    TOYKAUETOH
    AOOHTETYKU
    YHTOTKAEUO
    OTAHTKEOUY


Can Scramble() be optimised & fit into StringMod() ? Rolling Eyes

like StringMod("AUTOHOTKEY","Scramble")

Regards, Smile
_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
polyethene



Joined: 11 Aug 2004
Posts: 5248
Location: UK

PostPosted: Sat Mar 04, 2006 6:42 pm    Post subject: Reply with quote

Goyyah wrote:
Can Scramble() be optimised & fit into StringMod() ? Rolling Eyes
Done (http://www.autohotkey.net/~Titan/dl/StringMod.ahk)
_________________
GitHubScriptsIronAHK Contact by email not private message.


Last edited by polyethene on Wed Feb 17, 2010 5:04 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Sat Mar 04, 2006 6:47 pm    Post subject: Reply with quote

These are the functions I am using.
Code:
CharDrop(String,Chars) {
   Loop Parse, Chars
      StringReplace String, String, %A_LoopField%,,All
   Return String
}

CharKeep(String,Chars) {
   Loop Parse, String
      IfInString Chars, %A_LoopField%
         out = %out%%A_LoopField%
   Return out
}
They are simpler, but there are no branches with parameter comparison inside, so they must be faster. Most of the time, they are sufficient. They are so short that you normally just inline them, whithout the function wrapper around. Test them with
Code:
Text = *asd,f./?x
MsgBox % CharDrop(Text,"*,?")
MsgBox % CharDrop(Text,".,?/x")
MsgBox % CharKeep(Text,"dsa")
MsgBox % CharKeep(Text,"x,?f")
Creating a monster function, which does everything, might not be a very good idea. It will be slow, and if you only need one of its functionality, why would you include a large function and inflate your code?
Back to top
View user's profile Send private message
polyethene



Joined: 11 Aug 2004
Posts: 5248
Location: UK

PostPosted: Sat Mar 04, 2006 7:01 pm    Post subject: Reply with quote

Laszlo wrote:
Creating a monster function, which does everything, might not be a very good idea. It will be slow, and if you only need one of its functionality, why would you include a large function and inflate your code?
StringMod() is quite efficient (at least my version anyway) as it skips code that would not be needed to perform a given action. As the name itself implies, it's a fairly large combined collection of different string manipulation features that can be useful for numerous purposes. I do agree that it's large in code size, but it's easy to chop off the bits of code you don't need.
_________________
GitHubScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Sat Mar 04, 2006 7:17 pm    Post subject: Reply with quote

Titan wrote:
StringMod() is quite efficient (at least my version anyway) ... it's easy to chop off the bits of code you don't need.
Inside the parse loop, you check at each character if the command is Rot, Flip, Replace, Only or something else. It is a bunch of comparisons, branches for each character. This way you save a few lines of code, but the function would be several times slower than necessary. Until AHK has no optimizing compiler, cutting up large functions is faster and easier to maintain. Also, deleting unnecessary functions would require the user to understand, edit and test the code.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sun Mar 05, 2006 7:16 am    Post subject: Reply with quote

Dear Titan, Very Happy

You wrote:
Goyyah wrote:
Can Scramble() be optimised & fit into StringMod() ? Rolling Eyes
Done (http://www.autohotkey.net/~Titan/dl/StringMod.ahk)


Thanks a lot! Smile Smile
So quick!.. You are a Wizard!

Regards, Smile
_________________
URLGet - Internet Explorer based Downloader


Last edited by SKAN on Sun Mar 05, 2006 8:11 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
SKAN



Joined: 26 Dec 2005
Posts: 8688

PostPosted: Sun Mar 05, 2006 7:36 am    Post subject: Reply with quote

Dear Laszlo, Smile

You wrote:
Creating a monster function, which does everything, might not be a very good idea. It will be slow, and if you only need one of its functionality, why would you include a large function and inflate your code?


Well, I need this function for a word game, in which I will be using most of the functionality of StrMod(). I will be posting the word game here.

You further wrote:
Until AHK has no optimizing compiler, cutting up large functions is faster and easier to maintain. Also, deleting unnecessary functions would require the user to understand, edit and test the code


Maybe, its a valid point. I will put on the first post the breakdown of StringMod() functionality.
Omit()
Only()
Flip()
Replace()
Scramble()


Titan may have to help me with Rot13() and Rot47() I guess.

and, let the users decide what they want to have.
IMHO, StringMod() is a good example of adding more power into one single Function. Also an example for Team work

Regards, Smile
_________________
URLGet - Internet Explorer based Downloader
Back to top
View user's profile Send private message Send e-mail
PhiLho



Joined: 27 Dec 2005
Posts: 6836
Location: France (near Paris)

PostPosted: Sun Mar 05, 2006 9:38 am    Post subject: Reply with quote

Laszlo has a point that I wanted to make myself...
I played with the code given by Goyyah (and his algorithm) because it was fun, and the functions were, at start, kind of closely related.
Introducing the Rot functions was borderline...
Pushing functionnalities like scramble seems out of the scope of the function (despite the very generic function name), outside the initial algorithm because it no longer acts on individual characters, choosing what to do on them, but it changes char order, operating at global string scope. (Same for flip, but it is simple enough to be similar to the other functions.)

Having spent quite some time in both the Unix and the Windows, I am sometime splitted between Unix philosophy - make small programs doing little things, but powerful when combined using shell scripting, pipes, redirections etc., and the Windows philosophy - see MS Office or the UltraEdit juggernaut that seems to seduce many users: combining the base text editor with an hex editor, a FTP program, a diff, replacing in files and what's not.

It is seducing indeed: install one program and get most of the tools you need at once, under a consistent interface.
But it is limiting: what if you don't need the FTP? It takes disk space and inteface real estate for nothing. What if the diff doesn't offer all the features you need? You can use another diff tool (WinMerge is good Smile) but then you have a feature that is unused again.
Using separate tools has the advantage of offering flexibility: you get the right tools for you, and if you find a better one, you can switch.
And if you want a unique install program, use NSIS or some other install program (not InstallShield, better suited for monster programs like Office than to install small freewares, creating install programs twice the size of the installed binaries...).

Back to the topic, you can combine the best of both worlds: create several small, efficient satellite functions, and if really you like/need a consistent interface, create a StringMod function that calls these little functions depending on the asked task.
This way, it is easier to pick only the functions you need without having to hack the big function.

Now, Goyyah has a point too: making this function was fun and allowed to exchange points of view on coding! Smile
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
BoBo
Guest





PostPosted: Sun Mar 05, 2006 11:59 am    Post subject: Reply with quote

Beside the fact that from a(n old fashioned) users point of view - not to waste disk space/memory (regardless that his become cheap) is something I'm still attracted to - I've swapped from the "one script fits all" fshioned scripting to a more modulized form, using #Includes as much as possible. It has decreased the time I wasted to identify a piece of code and its dependencies within a huge script. And maintenance aka an Upgrade/Update/Replacement has become definitely more easiely.

JM2€C. Cool
Back to top
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  Next
Page 2 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