Comparing 2 Strings
I just have a question for anyone that i would like to know the answer or a link to where I can find it.
I am trying to find java code that when ran it will compare two different strings and output html of the two strings and highlight or show me somehow what is different or the same between the two strings.
Any help is appreciated, thank you.
> I am trying to find java code that when ran it will
> compare two different strings and output html of the
> two strings and highlight or show me somehow what is
> different or the same between the two strings.
Consider writing your problem statement into multiple sentences/parts. See how you could solve each part.
As far as I see your problem specification is too vague. You could do a character by character comparison of the strings and display the differences or similarities. Maybe you want a colored output in a html?
That's not alot of information. If by String you might mean the entire contents of a file (two different files, that is), then you might be well served by creating a Process that runs the System command 'fc' (Win) or 'diff' (Unix), for instance.
On the other hand, if by String you just mean relatively small character Strings like: "This new shiny PC is mine" vs " That new dusty PC is yours" ... and you wanna have carrots pointing to each and every character that is different, extra, the like, then either:
>Start coding
>Start Googling
When you get your output all set to display, you'll wrap it in html by appending to the String/s.
Ok well to be more specific.I am talking about comparing two java files and i want the output from the two to show me what the difference is between them and I want the difference to be colored so I know what is different.
So you want to write a diff tool?
> yes, i guess soGoogle results: [url http://www.google.com/search?q=java+diff+tool&sourceid=mozilla-search&start=0&start=0&ie=utf-8&oe=utf-8&client=firefox-a&rls=org.mozilla:en-US:official]java diff tool[/url]~Bill
Bill, thank you for the link, I found what I was looking for in a diff tool
ExamDiff
I do have another question though, for anyone that is familiar with the tool above, what it does is take 2 files and then shows what the differencees are between them, highlighting them in different colors depending on how they are different from each other. My question is: Is there a block of code that you can actually type into the files that I want to compare, like into the top of one of the java files? And if there is and someone knows an example of it or where I can find one, then I would greatly appreciate the link or example. Thanks
You are welcome."My question is: Is there a block of code that you can actually type into the files that I want to compare, like into the top of one of the java files?"Please rephrase your question.
Instead of using the ExamDiff tool, is there a way to type in java code into one, or both of the files that when the files are run, will compare the two files and do the same thing that the diff tool is doing?
i have no idea what you are asking, yet i am going to say:try using the diff that comes with eclipse. its good. if you want a good standalone tool, ive heard good things about this: http://kdiff3.sourceforge.net/
I honestly had no idea that there was a diff tool that cam standard with eclipse, can you tell me when i can find it?
On any of the right-click menus there should be a Compare Withoption. If you select two files, one of the choices will be "Each Other".
I tried using the Compare With ->It did absolutely nothing to help me compare two files, there wasnt even an option there so I could do it.
> On any of the right-click menus there should be a> Compare With> option. If you select two files, one of the choices> will be "Each Other".Does anyone know what he was talking about?I see the "Each Other", but i cant click it.
If you have two files selected, and the Each Other option isn'tavailable, then I don't t know what to tell you.
It's not letting me select two java files at the same time in eclipse.Do I have to select them on the left or what?
Yes, in Package Explorer or Navigator, left click on one file. Holdingdown Ctrl, left click on another file. Now both should be selected.Right click anywhere in the Package Explorer/Navigator panel,select Compare With -> Each Other.
OK thank you, i was just trying it in the wrong spot,It worked but it is just the same thing as my ExamDiff except a little less detailed.Do you know of a way i can put code into the files so when ran it will do pretty much the same thing?
> > On any of the right-click menus there should be a
> > Compare With
> > option. If you select two files, one of the
> choices
> > will be "Each Other".
>
> Does anyone know what he was talking about?
> I see the "Each Other", but i cant click it.
Did you select the files that you want to compare?
> OK thank you, i was just trying it in the wrong
> spot,
> It worked but it is just the same thing as my
> ExamDiff except a little less detailed.
>
> Do you know of a way i can put code into the files so
> when ran it will do pretty much the same thing?
I translate this to mean: Are there any java commands that can be added to a .java source file, such that if two .java source files that have such code are compared using a file comparison tool, will compare according to the specific 'compare rules' implied by the commands within the source files
If this is what you mean then I have no idea, but since there is always someone working on something perhaps searching the web will turn up something.
If this is not what you mean, then I think you have try harder to make your question clearer. Regards,
~Bill