Click here to Skip to main content
16,020,249 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
<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>

I want to replace the things with #Name#,#designation# etc with original data from code behind pl help me in doing it
Posted
Comments
manognya kota 27-Jan-12 1:04am    
use string replace

string correctString = errString.Replace("docment", "document");
Lakamraju Raghuram 27-Jan-12 1:07am    
<td>#Name#</td>
<td>#Department#</td>
<td>#Designation#</td>

Will you have repetition of the above block or will you have only one block of this kind ?

 
Share this answer
 
Comments
Espen Harlinn 27-Jan-12 3:32am    
5'ed!
Amir Mahfoozi 29-Jan-12 8:05am    
+5
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
 
Share this answer
 
v2
Comments
Lakamraju Raghuram 27-Jan-12 1:26am    
Good approach. My 5
Sergey Alexandrovich Kryukov 27-Jan-12 1:43am    
Thank you, Lakamraju.
--SA
Supriya Srivastav 27-Jan-12 2:41am    
My +5 too.
Sergey Alexandrovich Kryukov 27-Jan-12 2:54am    
Thank you, Supriya.
--SA
Espen Harlinn 27-Jan-12 3:32am    
5'ed!
I use StringTemplate[^] for this purpose. It's available for .Net and Java, mature and quite flexible.

Best regards
Espen Harlinn
 
Share this answer
 
Comments
thatraja 27-Jan-12 4:05am    
It's new to me, 5!
Espen Harlinn 27-Jan-12 4:17am    
Thank you thatraja!
Sergey Alexandrovich Kryukov 27-Jan-12 4:34am    
Isn't it an overkill? Not sure though, my 5.
--SA
Espen Harlinn 27-Jan-12 4:42am    
Thank you Sergey!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900