-
Notifications
You must be signed in to change notification settings - Fork 922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding CaseSensitive parameter to StrReplace. #103
Conversation
New: ReplacedStr := StrReplace(Haystack, SearchText [, ReplaceText, CaseSensitive := false, OutputVarCount, Limit := -1]) Implementation is copied from BIF_InStr. Reason for change: convenience.
This seems like it could be useful, but I wonder: how often would it be used, and how often are the OutputVarCount and Limit parameters used? It is already possible to control the case-sensitivity of StrReplace (though perhaps not in the most convenient way), whereas OutputVarCount and Limit provide functionality that would otherwise require either a custom replacement function or RegExReplace. The current parameter order is identical to RegExReplace, which aides memorization. I couldn't find any instance of StrReplace with more than three parameters in any of my scripts, but I know I have used OutputVarCount (or at least ErrorLevel with StringReplace). I do not recall having ever used StringCaseSense with StrReplace/StringReplace, although that might be because I am comfortable with regex. (I'm not sure that I've used StringCaseSense at all.) |
Hello.
In one sense it will always be used, that is, since not specifying the parameter is equivalent to passing
I think Regarding the parameter order, I'm quite neutral to it. I made a guess that the new parameter would be specified more often than the others. Whenever I use the Cheers. |
I would add StartPos (consistent with RegExReplace) and CaseSensitive parameters: (I occasionally find Limit useful for restricting replacements to the first instance.) |
Here's a possible solution for StrReplace. Parameters1 Haystack (and a StrCount function) Proposalsmodify StrReplace (before/after) (2 new params, 1 swap): introduce StrCount (AHK v1/v2) (params match InStr, although StartingPos could be omitted until fully discussed/scrutinised): Rationale
for reference (InStr/RegExReplace): I wrote the 2 functions as custom AHK functions and they neatly solved all my replace/count/StringCaseSense woes. Conversion cost re. the Count parameterThe conversion cost was very low: [I had 73 of these] [I had 40 of these] [I had 17 of these] That's of around 1774 StrReplace instances. |
Hello 👋
New:
Implementation is copied from
BIF_InStr
.Reason for change: convenience.