问题
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 ?
回答1:
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
回答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=(.*?)>";
来源:https://stackoverflow.com/questions/34859351/how-to-replace-dynamic-string-values-in-asp-net