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 ?

mck
  • 978
  • 3
  • 14
  • 38

2 Answers2

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=(.*?)>";
ED-209
  • 4,706
  • 2
  • 21
  • 26
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

Ian Grainger
  • 5,148
  • 3
  • 46
  • 72
  • @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 – Ian Grainger Jan 18 '16 at 16:32