StringReplace vs StrReplace vs RegExReplace

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User
Posts: 407
Joined: 26 Jun 2017, 08:12

StringReplace vs StrReplace vs RegExReplace

19 Sep 2017, 21:56

StringReplace (Command)

StrReplace (Function)

RegExReplace (Function)

Which one is faster? StringReplace? Any script available out there for testing purpose only?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: StringReplace vs StrReplace vs RegExReplace

20 Sep 2017, 01:19

It will depend on what you are doing of course, but in most cases, if you can do it with strReplace (or StringReplace), it will be fastest, especially if you can use StringCaseSens, On. The difference between strReplace and stringReplace is probably very small.

Cheers.
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: StringReplace vs StrReplace vs RegExReplace

20 Sep 2017, 07:40

I prefer to use RegExReplace because I'm used it it, but I do think it needs a bit of a fix up.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

User
Posts: 407
Joined: 26 Jun 2017, 08:12

Re: StringReplace vs StrReplace vs RegExReplace

20 Sep 2017, 08:53

Is StrReplace function based on StringReplace command or based on RegExReplace function?

If it's based on StringReplace command, so it means that StringReplace command is automatically faster?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: StringReplace vs StrReplace vs RegExReplace

20 Sep 2017, 09:09

To answer your two questions:
- StrReplace aims to replace StringReplace and to be a function version of it, but is modelled to resemble RegExReplace. In terms of version number, StrReplace is relatively new (1.1.21.00 - March 28, 2015).
- To find out which of two commands/functions/approaches is faster, try benchmark tests, i.e. repeat the same procedure say ~100000 times, and compare speeds to be sure. E.g.
[Speedtest] Bitwise Hacks - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=37217

StrReplace v. StringReplace:
- StrReplace and StringReplace should be roughly the same speed-wise.
- StringReplace will be removed in AHK v2.
- StringReplace had various disadvantages:
- it has replace once as default (StrReplace has replace all)
- the awkward UseErrorLevel approach to count replacements (StrReplace uses an output variable)
- it's a command not a function, so you can't do direct output (unlike InStr/StrReplace/RegExReplace), before StrReplace was available people were using RegExReplace to achieve this

StrReplace v. RegExReplace:
- StrReplace has the advantage over RegExReplace, that it's faster and you don't have to escape special characters
- RegExReplace has the advantage over StrReplace, of all the special RegEx replacement options
- RegExReplace is generally slower than StrReplace. Even using StrReplace 26/52 times, can be faster than one-liners like: RegExReplace(vText, "[A-Za-z]")
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Aqualest, OrangeCat and 358 guests