i have an expression that can evaluate to “rootfolder\\subfolder”. I want to replace the double backslash with a single one, but have problems creating the correct expression.
These expressions validate, but fail to produce the desired value:
Folder\\SubFolder.Replace("\\","\")
“Folder\\SubFolder”.Replace("\\","\")
This one does not validate:
$Folder\\SubFolder.Replace("\\","\")$
The issue here is that the backslash escapes the " character in function parameters. This is so we can allow the following expression $Utils.GetString("He said \"Yes\"").Replace("\"Yes\"",""\"No\"")$
The error you are seeing with $Utils.GetString(“Branch: Folder\\SubFolder”).Replace("\\","\")$ is because the backslash is escaping the final quote of each parameter. The expression parser is expecting another ".
Unfortunately, you can’t currently escape the escape character. We have been working on this today, and the next version with allow you to escape the backslashes as follows $Utils.GetString(“Branch: Folder\\\\SubFolder”).Replace("\\\\","\\")$. This should be available in the next couple of days.
I’m guessing that you won’t be entering Folder\\SubFolder directly (otherwise you could just enter Folder\SubFolder but would be using a variable, so note that the syntax to use would be $Utils.GetString(%branchFolder%).Replace("\\\\","\\")$
Doubling the backslash is what i tried in first place.
Indeed i am modifying a string that gets created dynamically.
Such as:
\Folder1\Folder2\$Source.MyRepo.BranchName.Replace(“master”,"")$\$Build.Version$
In case the word “master” gets deleted, the resulting string will contain a double backslash.
That is what i want to use eventually:
$Utils.GetString("\Folder1\Folder2\$Source.MyRepo.BranchName.Replace(“master”,"")$\$Build.Version$ “).Replace(”\\","\")$
In other words, the created string will be embraced by a call to Utils.GetString.
i’ll give the first option a try as soon as the next build will be released. I don’t consider CI’s actions for my use case, as the expression is more complex as what i have provided for demonstration purposes.