using System;
namespace Benq.HI4.Homework.Demo.CompareStr
{
public class CompareString
{
public static void Main()
{
string str1=Console.ReadLine();
string str2=Console.ReadLine();
int countstr1=str1.Length;
int countSame=0;
for(int i=0;i<countstr1;i++)
{
if(str1[i]==str2[i])
{
countSame++;
}
}
Console.WriteLine("相同字符串的数目为:{0}",countSame);
}
}
}

解决方案 »

  1.   

    用正则表达式,Regex类和Match类,查一下MSDN你就知道了。
      

  2.   

    str1.Text.Trim().Length
    str2.Text.Trim().Length
      

  3.   

    public class CharComp
    {
      
      public static void Main()
      {
         string str1="dalkjfalds";
         string str2="adfasdfadsf";
        
         int Count=0;     char[] ch=GetCh(str2);//获取str2中的不含重复字符的数组,
         for (int i=0;i<ch.Length;i++)
          {
              if (str1.IndexOf(ch[i])>-1)
                   Count++;
           }
      }  public static char[] GetCh(string str)
      {
        //从略
       }
    }
      

  4.   

    我是说做的web,比如str1="qsdf"; str2="qwde"; 比较这两个字符串中相同的字符数目是多少
    ,能写个例子吗,谢了!
      

  5.   

    对了,楼上的楼上,那个GetCh部分是什么啊?
      

  6.   

    还是写一个吧:
    public static char[] GetCh(string str)
      {
        StringBuilder result=new StringBuilder();
        char ch=str.ToCharArray();    for(int i=0;i<ch.Length;i++)
        {
          if (result.ToString().IndexOf(ch[i]) == -1)
               result.Append(ch[i]);
        }    return result.ToString().ToCharArray();
       }
      

  7.   

    还是写一个吧:
    public static char[] GetCh(string str)
      {
        StringBuilder result=new StringBuilder();
        char ch=str.ToCharArray();    for(int i=0;i<ch.Length;i++)
        {
          if (result.ToString().IndexOf(ch[i]) == -1)
               result.Append(ch[i]);
        }    return result.ToString().ToCharArray();
       }