I have this string XXX:ABC
. I want to remove XXX:
so that the string becomes ABC
.
The variable Symbol
contains the string XXX:ABC
.
The code as follows:
MsgBox, Symbol %Symbol%
SearchText := "XXX:"
ReplaceText := ""
StringReplace, newSymbol, Symbol, SearchText, ReplaceText, ALL
MsgBox, newSymbol %newSymbol%
From the message box output, newSymbol
content is the same as Symbol
. Can someone tell me what is wrong with my code?
I am using Autohotkey v1.1.14.03.
For command parameters, you have to distinguish between variable parameters and value parameters.
StringReplace
for instance has the following argument list:The docs say furthermore:
As you can see, some parameters are expected to be variable names, whereas others are expected to be values like strings or numbers. You can use variable contents as value parameters by either enclosing them in percent signs or using them within an expression:
With the newer StrReplace() function I noticed I could not use it with variables for whatever reason. And the documentation here: https://autohotkey.com/docs/commands/StringReplace.htm is lacking an example. After a lot of tests, couldn't figure it out. So I wrote a "polyfill" for StrReplace, complete with test code.
Also, be aware that trimming out newlines in your data is harder than it should be as well. And will be bound to throw a monkey wrench into whatever string parsing you are doing.