如何替换asp.net中的动态字符串值? [英] How to replace dynamic string values in asp.net?
本文介绍了如何替换asp.net中的动态字符串值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,要求用换行符替换文本.我的代码是
In my application requirement are to replace text with line break. Mine code is
pageText = pageText.Replace("<td style=\"width:23.0769230769231%;\">", "<br>");
此处的宽度值是动态的,这对于不同的pdf页面是不同的.如何使用string.Replace或Regex将整个字符串替换为换行符?
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 ?
推荐答案
您想要一个正则表达式,它将替换字符串:< td style = \" width:X; \>""
< br>"
其中X是任何数字?
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在这里摆弄: https://dotnetfiddle.net/30QCRP
.NET fiddle here: https://dotnetfiddle.net/30QCRP
这篇关于如何替换asp.net中的动态字符串值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文