-1

I have got the path using the following:

Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)

But the path I get is this:

C:\Users\test\AppData\Roaming\MetaQuotes\Agent-127.0.0.1-3000\Better_Result\Check\Libraries\x64

I want to replace this Agent-127.0.0.1-3000 with Latest. The Phrase Agent-127.0.0.1-3000 is not fixed but it always starts with Agent.

Hence, please let me know what I can do.
The final output I want is:

C:\Users\test\AppData\Roaming\MetaQuotes\Latest\Better_Result\Check\

I do not want Libraries\x64 also.
Please let me know.

Jaffer Wilson
  • 7,029
  • 10
  • 62
  • 139
  • 1
    `path = Regex.Replace(path, @"\bAgent-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}-\d+\b", "Latest")`. And for the second requirement, refer to [this post](https://stackoverflow.com/q/14899422/8967612) (or you can achieve it with substitution as well). – 41686d6564 stands w. Palestine Nov 02 '20 at 10:43

1 Answers1

1

You could use regex:

var newPath= Regex.Replace(oldPath,@"(?<=\\)Agent[^\\]*","Latest");
Magnetron
  • 7,495
  • 1
  • 25
  • 41