0

In my application requirement are to replace text with line break. Mine code is

pageText = pageText.Replace("<td style=\"width:23.0769230769231%;\">", "<br>");

Here width value is dynamic which is different for different pdf pages. How to replace this whole string with line break by using string.Replace or using Regex ?

0

2 Answers 2

2

You want a regex which will replace the string: "<td style=\"width:X;\">" with "<br>" where X is any number?

Console.WriteLine(Regex.Replace(input, "<td style=\"width:\\d+\\.?\\d*%;\">", "<br>"));

.NET fiddle here: https://dotnetfiddle.net/30QCRP

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

1 Comment

@Tokn I wanted to test some date stuff earlier and typed dotnetfiddle into Google. I assumed it would be created eventually. I was RIGHT! :D
2

Try this:

  string pattern = "<(.*?)>";
  string replacement = "<br>";
  Regex rgx = new Regex(pattern);
  string result = rgx.Replace(input, replacement);

Or yo could be more specific if you start with this:

string pattern = "<td style=(.*?)>";

Comments

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.