100分!!!请问,如何实现类似于 windiff的文本比较功能?有没有现成是组件或第三方控件啊?就是说,给你2个文本字符串,要求输出一张对比表格,分别用不同的颜色标示出2个文本不同的地方。
请有相关经验的高手帮忙,谢谢拉!

解决方案 »

  1.   

    windiff我都用过,不知道你要的是不是这样的效果
    private ArrayList CompTwoString(string A,string B)
    {
    ArrayList al =new ArrayList();
    string[] result =new string[2]{string.Empty,string.Empty};
    char[] As  =A.ToCharArray();
    char[] Bs  =B.ToCharArray();
    int CompCount =(As.Length<Bs.Length?As.Length:Bs.Length);
    for(int i=0;i<CompCount;i++)
    {
    if(As[i]==Bs[i])
    {
    result[0] +=As[i].ToString();
    result[1] +=Bs[i].ToString();
    }
    else
    {
    result[0]+=("<FONT color='red' face='宋体'>"+As[i]+"</FONT>");
    result[1]+=("<FONT color='red' face='宋体'>"+Bs[i]+"</FONT>");
    }
    }
    if(A.Length>CompCount)
    result[0]+=("<FONT color='red' face='宋体'>"+A.Substring(CompCount,A.Length-CompCount)+"</FONT>");
    if(B.Length>CompCount)
    result[1]+=("<FONT color='red' face='宋体'>"+B.Substring(CompCount,B.Length-CompCount)+"</FONT>"); al.Add(result[0]);
    al.Add(result[1]); return al;
    }
    private void Button2_Click(object sender, System.EventArgs e)
    { DataGrid1.DataSource =CompTwoString("abcdess","axcdsadsfds");
    DataGrid1.DataBind(); }