1

I have a long HTML page as a string. Throughout, I have image tags with text like this:

cid:@(Model.MyImage)

I have strings storing the path and file extension. I'd like to replace the above to get

[mypath]MyImage.[myExtension]

So I'd like to capture that MyImage text and use it in my new string - then get rid of all the cid: stuff and put the standard path in.

So, cid:@(Model.MainChart) might become C:\MainChart.png

EDIT

Per the answer below, the question has been answered nicely. Example of usage below:

string first = @"<img src=""cid:@(Model.FirstOne)"" style=""max-width:600px;"" then <img src=""cid:@(Model.Another)"" style=""max-width:600px;"")";
            string pathPrefix = @"C:\";
            string extension = ".png";
            string newPath = Regex.Replace(first, @"cid:@\(Model\.([^)]*)\)", pathPrefix + "$1" + extension);

1 Answer 1

3

Here is my suggestion for you. The Regex is:

cid:@\(Model\.([^)]*)\)

and the replacement string should contain a $1 for the found image.

Sign up to request clarification or add additional context in comments.

2 Comments

What did you mean by "and the replacement string should contain a $1 for the found image." ?
This works like a charm, thanks Fischermaen. I'll post the worked solution in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.