|
|
No, it does not. By the way, this is the Weird and Wonderful , or Coding Horrors forum - I really intended to place it here, because it is quite a WTF, and I do not expect a sensible answer for it (OK, if you know it, let me here it).
It rather looks like a philisophical design decision: since Rtf is always longer than SelectedRtf , the whole is more than the sum of its parts...
|
|
|
|
|
Try this test to get a better Idea.
Create a test project with a richtextbox and a normal text box.
two buttons and a label to show the length
In VB.net it would look like.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim selLen As Integer
Dim selectedRtf As String = RichTextBox1.SelectedRtf
selLen = selectedRtf.Length
Label1.Text = selLen.ToString
TextBox1.Text = selectedRtf
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim selLen As Integer
Dim selectedRtf As String = RichTextBox1.Rtf
selLen = selectedRtf.Length
Label1.Text = selLen.ToString
TextBox1.Text = selectedRtf
End Sub
Using a converter to convert to C# it would look like this.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
int selLen = 0;
string selectedRtf = RichTextBox1.SelectedRtf;
selLen = selectedRtf.Length;
Label1.Text = selLen.ToString;
TextBox1.Text = selectedRtf;
}
private void Button2_Click(System.Object sender, System.EventArgs e)
{
int selLen = 0;
string selectedRtf = RichTextBox1.Rtf;
selLen = selectedRtf.Length;
Label1.Text = selLen.ToString;
TextBox1.Text = selectedRtf;
}
Next create some text in wordpad with different formating. Copy paste to the richtextbox (ctl+V)
what this code does is gets the length of the string, the entire string with the hidden formating and copies it to the plain textbox to view all of it.
You can add the line to select all or just select it on the RTF box.
After going back and forth between the buttons you may notice that the second one shows more formatting and thus it is longer.
|
|
|
|
|
I'm not certain, but suspect it is due to the fact that an RTF document contains various sections in addition to the formatting codes needed. Here's one version of the spec: RTF 1.7[^] (not the latest, but most should be similar).
A bit like copying HTML to clipboard - if just the markup is copied, other information supplied in the header section may be omitted, so styles etc. wouldn't work correctly. The SelectedText may contain just enough of these for the selection, while the Rtf property will, presumably, include all those in the entire RTF "document" including standard "document level" header sections (a bit like the <head> section in HTML).
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
Agree.
|
|
|
|
|
Sometimes I have the impression to work for Augeas[^] Stables Inc, but actually I am expected to produce more dung than to get rid of it...
In the 13395 lines of code of the main window of one of our applications, I found this little gem (really little - only 320 loc) whose functionality I'll need in a new application (a little anonymized):
private void DoSomething()
{
...
#region do X
...
#endregion
#region do Y
...
#endregion
#region do Z
...
#endregion
#region do A
...
#endregion
#region do B
if (some condition)
{
#region do C
...
#endregion
}
else
{
#region do D
...
#endregion
}
#endregion
...
#region do E
try
{
switch (some swicth)
{
#region do F
case ...
break;
#endregion
#region do G
case ...
break;
#endregion
#region do H
case ...
break;
#endregion
#region do I
case ...
break;
#endregion
}
...
#endregion
}
Of course with some extra try...catch inside the regions or other try...catch.
Well, at least, it looks like the functionality I need to transfer to the new application is - with the exception of some member variables - in that one single function, and not scattered all over the class...
"Have you heard of 'Clean Code' by Robert C. Martin? You can download it from the web", said the guy who uses to write such functions.
|
|
|
|
|
#region wow
Console.Writeline("Wow!");
#endregion
|
|
|
|
|
It's a form of modular code: each module goes in it's own region so you don't get the visual clutter associated with methods...
Find a new job! Life is too short...
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Why? In order to get experience with even more styles of WTF used in those different places?
|
|
|
|
|
So you're saying "better the crap you know"?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I'm guessing it's a regional issue.
What do you get when you cross a joke with a rhetorical question?
|
|
|
|
|
I guess stupidity is not regional, it's universal
|
|
|
|
|
To write that and then quote Clean Code is a special level of genius!
|
|
|
|
|
If a little of something is good, then a whole lot of it must be better, right?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Bernhard Hiller wrote: In the 13395 lines of code of the main window
Bernhard Hiller wrote: In the 13395 lines of code
Bernhard Hiller wrote: 13395
What?
|
|
|
|
|
That's clean code, isn't it?
|
|
|
|
|
I came across this java code. (I changed the class name to SingletonClass)
private static SingletonClass instance;
public SingletonClass()
{
SingletonClass.instance = this;
}
public static SingletonClass getInstance()
{
return instance;
}
|
|
|
|
|
Singleton... public constructor... I don't see anything wrong here
Oh... And I'm curious what you do when you don't call the constructor at least once
|
|
|
|
|
Which of course is used like this:
SingletonClass myVerySingletonClass = (new SingletonClass()).getInstance();
or even better:
SingletonClass anInstanceThatWeDontUse = new SingletoneClass();
SingletonClass useThisInstead = anInstanceThatWeDontUse.getInstance();
Good stuff!
On the other hand, I actually have written code similar to this, except I don't call it a singleton of course. Granted, it's smelly code.
Quiz: What might be the reason to provide a static method that returns an instance of the class, when you know that there will ever only be one instance?
Marc
|
|
|
|
|
SingletonClass useThisInstead = anInstanceThatWeDontUse.getInstance();
This would actually generate a compile error as it getInstance() is a static method
|
|
|
|
|
Nicholas Marty wrote: This would actually generate a compile error as it getInstance() is a static method
Marc
|
|
|
|
|
Actually, in Java you are allowed to call a static method from an instance...
One of many dumb things Java does.
|
|
|
|
|
Uh... Somehow I mistook the code for c#... Somehow skipped that in the original post
At least in c# it isn't possible to do that and I'd think even Java should at least give a compiler warning about that
|
|
|
|
|
If there'll only ever be one instance, that's your typical singleton, isn't it? I don't really understand your quiz question.
I've done load-on-demand singletons in the past which may be what the doofus in charge of this example was going for, I suppose.
|
|
|
|