I want to use drawString to print a sentance but some parts of it has to be bold. What is the best way to do this? Yes, I have considered using two drawString. But is there a intelligent way of using two drawStrings if we have to.
We cannot make any assumtion about the length of the sentance. However it is prepared in a format.
eg:
Say hello to name. Good afternoon
name.
Thanks
This is my old question on MSDN & it was answered. It works good. I hope it is the thing you want to find.
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/8a050039-d74a-4ab5-9237-98615e10e303
Yes, you will have to call DrawString twice - you can write a small wrapper class (or extension method) that will do that for you.
Related
Thanks for someone who might be able to help me further, as I can't find an answer in the www right now. I actually program VB.net, but since this language is now dissolved and not further developed, I want to switch to C#. I am getting on well, because a lot of things are similar. There is only one method where I am stuck.
In vb.net I always liked to use the method:
mystring.split(seperator)(part)
to get a certain string from a CSV line and work with it. How does this work in C#? I know that I can load everything into an array, but I don't want to do that in this case. A simple split and the number of the element is enough. Can someone help me?
Seems like the same split method is what you need? It returns an array which you could store or just access directly. The difference being in C# you use [index] instead. So something like this:
string myFile = File.ReadAllText("myfile.txt");
string firstLine = myFile.Split("\r\n")[0];
Ok the title may be not correct but this is what i came as best
My question is this
Example 1
see , saw
I can convert see to saw with as
replace ee with aw
string srA = "see";
string srB = "saw";
srA = srB.Replace("aw", "ee");
Or lets say
show , shown
add n to original string
Now what i want it is, with minimum length of code, generating such procedures to any compared strings
Looking for your ideas how can i make it? Can i generate regexes automatically to apply and convert?
c# 6
Check diffplex and and see if it is what you need. If you want to create a custom algorithm, instead of using a 3rd party library just go through the code -it's open source.
You might also want to check this work for optimizations, but it might get complicated.
Then there's also Diff.NET.
Also this blog post is part of a series in implementing a diff tool.
If you're simply interested in learning more about the subject, your googling efforts should be directed to the Levenshtein algorithm.
I can only assume what your end goal is, and the time you're willing to invest in this, but I believe the first library should be enough for most needs.
What would be the best way to compare big paragraphs of text in order to tell the differences apart. For example string A and string B are the same except for a few missing words, how would I highlight these?
Originally I thought of breaking it down into word arrays, and comparing the elements. However this breaks down when a word is deleted or inserted.
Use a diff algorithm.
I saw this a few months back when I was working on a small project, but it might set you on the right track.
http://www.codeproject.com/KB/recipes/DiffAlgorithmCS.aspx
You want to look into Longest Common Subsequence algorithms. Most languages have a library which will do the dirty work for you, and here is one for C#. Searching for "C# diff" or "VB.Net diff" will help you find additional libraries that suit your needs.
Usually text difference is measured in terms of edit distance, which is essentially the number of character additions, deletions or changes necessary to transform one text into the other.
A common implementation of this algorithm uses dynamic programming.
Here is an implementaion of a Merge Engine that compares 2 html files and shows the highlighted differences: http://www.codeproject.com/KB/string/htmltextcompare.aspx
If it's a one-shot deal, save them both in MS Word and use the document compare function.
A Java version of this question was just answered, and, well, I don't know how to do this in .net.
So how do you calculate the display width of a string in C# / .net?
An alternative for Windows Forms is the static TextRenderer.MeasureText method.
Although restricted to integer sizes, this (in tandem with TextRenderer.DrawText) renders more accurate and much higher quality ClearType text than the Graphics.MeasureString/DrawString duo.
You've got the same problem in this question as was present in the Java question - not enough information! It will differ between WinForms and WPF.
For WinForms: Graphics.MeasureString
For WPF I'm not sure, but I suspect it will depend on the exact way you're drawing the text...
In WPF you would use FormattedText.
Graphics.MeasureString but its a bit crappy, as is explained and improved upon; here
You would use Graphics.MeasureString.
http://msdn.microsoft.com/en-us/library/6xe5hazb.aspx
Graphics.MeasureString([text to measure],[font being used to measure text]);
The resulting object will provide the following:
Other overloads of MeasureString also available.
I have two strings and would like to display the difference between them. For example, if I have the strings "I am from Mars" and "I am from Venus", the output could be "I am from Venus". (Typically used to show what changed in an audit log, etc.)
Is there a simple algorithm for this? I am using C# but I guess a generic algorithm could be adapted from any programming language.
Or is there a framework class/third-party library that will do this sort of thing?
Check this out: http://en.wikipedia.org/wiki/Diff#Algorithm
Also: http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
There is also an implementation described here: http://www.codeproject.com/KB/recipes/DiffAlgorithmCS.aspx