2016-08-24 6 views
0

私のアプリケーションでは、2つの文字列があり、それらの数を数えて挿入する単語を挿入する必要があります。たとえば :asp.netの2つの文字列の間で変化する単語を比較するには

string variable1="When you are writing server code you can never be sure what the IP address you see is refereeing to.In fact some users like it this way."; 
    string variable2="when are wrting server code yu cannn never be sure **Demo** what the address you is to.In fact **Demo1** some users like it this way"; 

結果は次のようになります。

Missing Words: you, see ,IP 
    Missing Words count: 3 

    Inserted: Demo, Demo1 
    Inserted Words count: 2 

    Modified words : wrting,yu ,cannn ,refering 
    Modified words count :4 

私はこれを試してみましたが、それは修正の言葉で適切に

string variable1="When you are writing server code you can never be sure what the IP address you see is refereeing to.In fact some users like it this way."; 
    string variable2="when are wrting server code yu cannn never be sure **Demo** what the IP address you see is to.In fact **Demo1** some users like it this way"; 

    //Missing Word Count  
    var result = variable1.Split(new char[] { ' ' }).Except(variable2.Split(new char[] { ' ' })).ToArray(); 
    count = result.Length; 
    Label2.Text += "Missing Word Count: " + count.ToString() + "<br/><br/>"; 
    for (int i = 0; i < count; i++) 
    { 
     Label1.Text += "Missing Word: " + result[i].ToString() + "<br/><br/>"; 
    } 


    //Insert Word 
    var result1 = variable2.Split(new char[] { ' ' }).Except(variable1.Split(new char[] { ' ' })).ToArray(); 
    count = 0; 
    count = result1.Length; 
    for (int i = 0; i < count; i++) 
    { 
     Label3.Text += "Insert Word: " + result1[i].ToString() + "<br/><br/>"; 

    } 
    Label4.Text += "Insert Word Count: " + count.ToString() + "<br/><br/>";  

    //Modifide Words 
    string[] tempArr1 = variable1.Split(' '); 
    string[] tempArr2 = variable2.Split(' '); 
    int counter = 0; 

    for (int i = 0; i < tempArr1.Length; i++) 
    { 
     if (tempArr1[i] != tempArr2[i]) 
     { 
      lblwords.text=tempArr1[i] + ", "+ tempArr2[i]; 
      counter++; 
     } 
    } 

を表示しない誰もがこれを行う方法に私を助けることができます。

ありがとう

+2

はこれを試す達成するためにLinqを使用することができますhttp://stackoverflow.com/questions/24887238/how-to-compare-two-rich-text-box -contents-and-highlight-the-those-that-are –

+0

この修正された単語のように表示する必要があります:wrting、yu、cannn、 修正単語数:4を参照してください。 –

+0

論理的には、variable1-missingwords + insertedwordsを変更し、variable2と比較する必要があります。 – kurakura88

答えて

1

あなたはこの

string s1 = "When you are writing server code you can never be sure what the IP address you see is refereeing to.In fact some users like it this way."; 
string s2 = "are wrting server code yu cannn never be sure what the IP address you see is to.In fact some users like it this way."; 
var list = s2.Split(' ').Where(x => (!s1.Split(' ').Contains(x))).ToList(); 

int count = list.Count; 
foreach (var item in list) 
{ 
//your code 
} 
+0

Hello Leopardお返事をありがとうございます。私は自分の質問を更新しました。ここで私のS2で私はデモとDemo1の言葉を持っている、これらの言葉はS1にありません。ここでは、デモとデモ1の単語を表示する必要はありません。なぜなら、それらはs1にないからです。ここで私が欲しいのは、ちょうど私はS1にある単語とs2に同じ単語をスペルミスで表示したいのです。 –

+0

@ User107これはあなたがスペルミスであることが分かりますが、あなたのプログラムはできません。 'Demo'と' cannn 'の両方の単語は 's1'と比べて未知の単語です。スペルミスを見つけるには、すべての単語が順番に並んでいる必要があります。 – Shaharyar

+0

こんにちは、私のコードを更新したらShaharyarが見えます。私の要件は、2つの大きな文字列(ドキュメント)の間に欠けている単語、挿入された単語、修正された単語を表示する必要があります。私は行方不明と言葉を挿入しているが、私は修正された言葉を得ていない私はこれを試している、あなたはそれが非常に緊急の要件だ私を助けてくださいお願いします。 –

関連する問題