2012-12-12 2 views
0

나는 richTextBox1과 richTextBox2를 한 단어 씩 비교하고있다.두 개의 RichTextBox를 비교하고 있습니까?

// collect words from ritchtextbox1 
String[] test = richtextbox1.text.Split(" ", StringSplitOptions.RemoveEmptyEntries); 

// find each word test to richtextbox2 
// if it is found then change back color of particular word to green of the 
// else change back color of particular word to red in richtextbox1 

test = richtextbox2.text.Split(" ", StringSplitOptions.RemoveEmptyEntries); 

// find each word in test to richtextbox1 
// if it is found then change back color of particular word to green of the 
// else change back color of particular word to red in richtextbox2 

어느 누구도 코드 구문에 약간의 도움이 될 수 있습니다. mateusz 코드의

메신저 복용 참조

String[] test = richtextbox1.text.Split(" ", StringSplitOptions.RemoveEmptyEntries); 
String[] test2 = richtextbox2.text.Split(" ", StringSplitOptions.RemoveEmptyEntries); 

bool wordNotFound=false; 

for (int i=0;i<test.lenght;i++) 
for (int j=0;j<test2.length;j++){ 
    if (test[i].equals(test2[j])){ 
     wordNotFound=true 
      break; 
      } 
    else wordNotFound=true; 
    } 

은 //// 여기에 나는이 두 개의 텍스트 상자가 메신저

if (wordNotFound) richTextBox1.BackColor = Color.Red; 
    else richTextBox1.BackColor = Color.Green; 

메신저 비교하지 다시 특정 단어 색상하지 전체 ritchtextbox을 변경해야 양쪽에 존재하는 각 단어의 유효성을 검사합니다. 사전을 하나의 richtextbox1로 취하는 맞춤법 검사와 같습니다. richtextbox2에서 맞춤법 [valid word]를 확인하십시오. 단어가 전혀 분할 귀찮게 왜 같은 순서로 될 경우 그 반대의 경우도 마찬가지 ...

+0

메신저가 양쪽에 존재하는 각 단어의 유효성을 검사합니다. 사전을 하나의 richtextbox1로 취하는 맞춤법 검사와 같습니다. richtextbox2에서 맞춤법 [valid word]를 확인하십시오. 그 반대의 경우 ... – Siva

+0

[가능한 두 개의 richtextbox 텍스트를 C#을 사용하여 비교하는 방법] (http : // stackoverflow.co.kr/questions/6782195/how-to-compare-2-richtextbox-text-using-c-sharp) –

+0

@ 0A0D 행마다 비교 Word에서 단어로 비교해야합니다 – Siva

답변

2
var validWords = new HashSet<string>(new string[] { "a","c","e" }); 
string[] wordsToCheck = new string[] { "a", "b", "c", "d", "e" }; 

var result = wordsToCheck.Select(w => new 
       { 
        Word = w, 
        IsValid = validWords.Contains(w) 
       }) 
       .ToList(); 

모든 단어가 유효한지 여부 만 알고 싶다면

var isOK = wordsToCheck.All(w => validWords.Contains(w)); 

,

는 PS : 물론, new string[]{}들 *

+1

고마워 이것이 정확히 내가 찾는 것입니다 ... – Siva

-1

당신은 TextBox2를

for(int i = 0; i < stringarray1.length; i++) 
{ 
for(int j = 0; j < stringarray2.length; j++) 
{ 
    if(stringarray1[i] == stringarray2[j]) 
    // we have a match 
} 
} 
+0

실제로 각 단어의 유효성을 검사하는 두 개의 텍스트 상자를 비교하지 않습니다. 양쪽에 존재하거나 존재하지 않는다. 사전을 하나의 richtextbox1로 취하는 맞춤법 검사와 같습니다. richtextbox2에서 맞춤법 [valid word]를 확인하십시오. 그 반대의 경우 ... – Siva

1

으로 TextBox1에 각 단어를 비교할 수 있을까?

if (richtexbox1.text.equals(richtexbox1.text)){ 
richTextBox1.BackColor = Color.Green; 
} else { 
richTextBox1.BackColor = Color.Red; 
} 

그렇지 않으면, 당신은 두 텍스트 상자 같은 단어가 포함 된 경우 찾으려하지만 다른 순서로 :이 확인 될 경우 , 내가 할 줄

String[] test = richtextbox1.text.Split(" ", StringSplitOptions.RemoveEmptyEntries); 
    String[] test2 = richtextbox2.text.Split(" ", StringSplitOptions.RemoveEmptyEntries); 

    bool wordNotFound=false; 

    for (int i=0;i<test.lenght;i++) 
    for (int j=0;j<test2.length;j++){ 
     if (test[i].equals(test2[j])){ 
      wordNotFound=false; 
       break; 
       } 
     else wordNotFound=true; 
     } 

    if (wordNotFound) richTextBox1.BackColor = Color.Red; 
     else richTextBox1.BackColor = Color.Green; 
+1

내부 루프에서 다음과 같아야합니다. wordNotFound = false; – Link

+0

여기에 특정 단어 색상이 변경되지 않았습니다 전체 richtextbox를 변경했습니다 – Siva

0
String[] test = richtextbox1.text.Split(" ", StringSplitOptions.RemoveEmptyEntries); 
    String[] test2 = richtextbox2.text.Split(" ", StringSplitOptions.RemoveEmptyEntries); 

rtb.Split(....) 오류를주고 대체한다;

오류 1에 가장 적합한 오버로드 된 메서드에 일치 '사항 String.split (문자열 [], System.StringSplitOptions)이'일부 무효 인수 C가 있습니다 사드 \ 문서 비주얼 스튜디오 2012 프로젝트 \를 \ \ 사용자 \ \ WindowsFormsApplication5 \ WindowsFormsApplication5 \ Form1.cs를 60 29 WindowsFormsApplication5

오류 2 인수 1 : 에 '문자열'에서 변환 할 수 없습니다 '문자열 []'C : 사드 \ 문서 비주얼 스튜디오를 \ \ \ 사용자 프로젝트 \ 2012 \ WindowsFormsApplication5 \ WindowsFormsApplication5 \ Form1.cs 60 53 WindowsFormsApplication5

관련 문제