Zoltan
Zoltan

Reputation: 63

c# change file link path using regex

I have problem with regex!

I want to change the filelink ""file:\\" to "file:\" but with this solution i can't because it kill all my other slashes.

"file:\\mail\attach\2015_02\random file name" This file link is in string variable.

Do you have any idea or other solution? Thx!

Upvotes: 1

Views: 276

Answers (2)

J.Jung
J.Jung

Reputation: 26

If you must use regex

const string originalPath = @"file:\\mail\attach\2015_02\random file name";
var newPath = Regex.Replace(originalPath, @"file:\\{2}(.+)", @"file:\$1");
Console.WriteLine(newPath);

Try this DotNetFiddle

Upvotes: 0

Florian Schmidinger
Florian Schmidinger

Reputation: 4692

no need for regex:

 fileLink = fileLink.Replace(@"file:\\",@"file:\");

and you are done

Upvotes: 6

Related Questions