类:public class Class1
{
public static void Replace(string[] s, string[] values)
{
if (s.Length != values.Length)
{
//出错提示
return;
}
System.IO.StreamReader sr = new System.IO.StreamReader(@"C:\a.html");
System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\d.html");
string str = sr.ReadToEnd();
for (int i = 0; i < s.Length; i++)
str = str.Replace(s[i], values[i]);
sw.Write(str);
sr.Close();
sw.Close();
return;
}
}调用方法:string[] s = new string[3] {"title", "news_time", "content"};
string[] values = new string[3] {"恭贺新春", "2005-2-9", "举国上下都在欢度2005年的春节..."};
Class1.Replace(s, values);
最后说明一句,这样做之后,默认编码是UTF-8

解决方案 »

  1.   

    谢谢 yufenfeila(雨纷飞啦),可以解决我的问题,但我还想知道如这种赋值方式
    myobjHtml.replaceStr("notic_title")="恭贺新春"; 的类是怎么编写的,因为我是在程序里调用到别人写的这个组件,(已经编译成dll),但我看不到源码,我很好奇,所以来这里问问
      

  2.   

    你这个是用C#写的?那你可以用Reflector反编译一下看看嘛