替换字符串中的内容 [英] To replace the contents in a string

查看:86
本文介绍了替换字符串中的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个带有一些HTML标记的文本文件,并且正在使用流阅读器读取此文本文件,现在字符串的内容类似于下面显示的代码
现在必须以该字符串格式将#Name#替换为Myname

Hi

I have a text file in which i have some HTML tags and I am reading this text file using a stream reader, now the contents of the string looks like the code displayed below
now in that string format i have to replace #Name# with the Myname

<html>
<body>
<h4>This is an Auto generated mail Please do not reply to this message</h4>
<table border=1>
<tr>
<td>Name</td>
<td>Department</td>
<td>Designation</td>
</tr>
<tr>  
<td>#Name#</td>
<td>#Department#</td>
<td>#Designation#</td> 
</tr>
</table>
</body>
</html>


我想将#Name#,#designation#等内容替换为pl后面的代码中的原始数据,以帮助我完成操作


I want to replace the things with #Name#,#designation# etc with original data from code behind pl help me in doing it

推荐答案

在这里查看这些文章
电子邮件模板 [ ^ ]
电子邮件模板:处理模板文件的通用解决方案 [ ^ ]
Here check these articles
Email Templates[^]
Email Templates: A generic solution to handle template files[^]


坏主意.相反,可以代替参数"{0}","{1}"和"{2}",并使用string.Format方法替换实际参数值.

请参阅:
http://msdn.microsoft.com/en-us/library/b1csw23d.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/txafckwd.aspx [ ^ ].

-SA
Bad idea. Instead, you can use in place of the parameters "{0}", "{1}" and "{2}" and use string.Format method to substitute actual parameter values.

Please see:
http://msdn.microsoft.com/en-us/library/b1csw23d.aspx[^],
http://msdn.microsoft.com/en-us/library/txafckwd.aspx[^].

—SA


我使用 StringTemplate [
I use StringTemplate[^] for this purpose. It''s available for .Net and Java, mature and quite flexible.

Best regards
Espen Harlinn


这篇关于替换字符串中的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆