[.net] How to compare text differences and how is the best way to mark the differences?
I am developing a text Comparer similar to
WinDiff / WinMerge. I am confused of comparing the
text because it did not work..
What I was trying to do were:
I compare the whole textBox text, if they are
different, I compare them per line, if they are
different, I compare them per word but what was
happening did not fill my expectation.
private: System::Void button8_Click(System::Object^
sender, System::EventArgs^ e) {
if ( String::Compare(textBox1->Text,textBox2->Text)
== 0 )
MessageBox::Show("Source file equals to Destination
file");
else { //tidak sama maka != 0 jadi bandingkan per
baris setelah itu per kata
for ( int i = 0 ; i < textBox1->Lines->Length ; i++)
for ( int j = 0 ; j < textBox2->Lines->Length ;
j++)
if
(String::Compare(textBox1->Lines->ToString(),textBox2->Lines[j]->ToString())
!= 0) {
MessageBox::Show("Different");
}
}
} //end of button8 click
And also I am confused how to mark the difference
since textBox don't support the text highlight
coloring..How is the best way to let user know the
different parts?
Can you help me, please..I am stucked for this
problem.
-----------------------------------------------------
2. I have other problem which is how to display
unicode characters? I need to display Japanese Kanji,
Hiragana, Katakana, Chinese, Korean and Thai
characters in the proper way..
I have tried this way:
textBox2->Text =
System::IO::File::ReadAllText(openFileDialog1->fileName,
System::Text::Encoding::Unicode);
but it still cannot display the text file containing
Japanese Kanji / Hiragana / Katakana well and THE
WORSE THING, a text file containing Latin(normal
ASCII) characters also displayed as Asian characters
but I don't know which characters they were.
Can you please tell me how to display all text file
well?
Thank you very much.
If you do not explicitly specify an encoding when reading text files it should automatically detect the encoding for you (assuming the files have a BOM you shouldn't have any problems).
As for highlighting text; you could use the RichTextBox class. Set a selection (with its SelectionStart and SelectionLength properties) then change the colour via the SelectionColor property (you can also change fonts and so on here).
To display East Asian characters you will need to set it to use a font containing the requisite glyphs, as it will not render them otherwise. MS Mincho and MS Gothic are good bets. Do bear in mind that these fonts are not usually installed by default on English versions of Windows.
As for highlighting text; you could use the RichTextBox class. Set a selection (with its SelectionStart and SelectionLength properties) then change the colour via the SelectionColor property (you can also change fonts and so on here).
To display East Asian characters you will need to set it to use a font containing the requisite glyphs, as it will not render them otherwise. MS Mincho and MS Gothic are good bets. Do bear in mind that these fonts are not usually installed by default on English versions of Windows.
1. I have successfully open a text file containing 1 Kanji character, 1 Katakana character, 1 Hiragana character and some normal Latin text. All of them displayed well.. But the text file I opened was in an UTF-8 encoding..So there is another problem, how if I open a non UTF-8(ANSI) text files? How to convert them to UTF-8 / Unicode?
In this application, user can open a file, edit it and save it back..Is it necessary to set the encoding into UTF-8 everytime user save the file?
2. How to specify the encoding when I read the text files like you said?
3. Yes, but after my code successfully check if 2 files are different, how can I know the word position? I mean like if we have error compiled in C++ / other language, if we double-click on the error, it will automatically point to the line containing that error. How to do that?
Are you sure if the RichTextBox will give highlight color? Because I have tried it but what happening was the textcolor that was changed and nothing highlighting the text..
What was wrong?
4. So before I read the text files, I need to set the textBox font first?
Can you please give me some code sample for each of my questions above to make this clearer?
Thank you very much..
[Edited by - chrisliando on February 10, 2008 6:46:29 PM]
In this application, user can open a file, edit it and save it back..Is it necessary to set the encoding into UTF-8 everytime user save the file?
2. How to specify the encoding when I read the text files like you said?
3. Yes, but after my code successfully check if 2 files are different, how can I know the word position? I mean like if we have error compiled in C++ / other language, if we double-click on the error, it will automatically point to the line containing that error. How to do that?
Are you sure if the RichTextBox will give highlight color? Because I have tried it but what happening was the textcolor that was changed and nothing highlighting the text..
What was wrong?
4. So before I read the text files, I need to set the textBox font first?
Can you please give me some code sample for each of my questions above to make this clearer?
Thank you very much..
[Edited by - chrisliando on February 10, 2008 6:46:29 PM]
Quote:Original post by chrisliando
1. I have successfully open a text file containing 1 Kanji character, 1 Katakana character, 1 Hiragana character and some normal Latin text. All of them displayed well.. But the text file I opened was in an UTF-8 encoding..So there is another problem, how if I open a non UTF-8(ANSI) text files? How to convert them to UTF-8 / Unicode?
In this application, user can open a file, edit it and save it back..Is it necessary to set the encoding into UTF-8 everytime user save the file?
2. How to specify the encoding when I read the text files like you said?
3. Yes, but after my code successfully check if 2 files are different, how can I know the word position? I mean like if we have error compiled in C++ / other language, if we double-click on the error, it will automatically point to the line containing that error. How to do that?
Are you sure if the RichTextBox will give highlight color? Because I have tried it but what happening was the textcolor that was changed and nothing highlighting the text..
What was wrong?
4. So before I read the text files, I need to set the textBox font first?
Can you please give me some code sample for each of my questions above to make this clearer?
Thank you very much..
1. You can use Notepad++ to convert UTF8 to Unicode
3. Try using richeditBox1.SelectionBackColor instead (half a second on Google and I found that)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement