The main form contains a TabControl with three tab pages that demonstrate String member methods, String shared methods, and StringWriter methods. Each tab page enables the user to enter string values and then execute String methods by clicking buttons. The underlying design contains a Method class and a Parameterclass. Each instance of the Method class represents a different String method. This design makes it easy to pass the values entered on the form to the appropriateString method.
Download Project
| Method |
Description |
| String..::.Insert
String..::.Remove |
These methods create and return new String objects. Many of these methods are overloaded and take one, two, or three parameters. The code may ignore some of the input fields in the form. |
| String..::.IndexOf
String..::.StartsWith
String..::.EndsWith |
These methods return information about an existing string, but do not create or modify String objects. |
| String..::.Format
String..::.Join |
These methods often need two Strings to complete a task, or create new strings, and are therefore implemented as Shared methods. |
| StringBuilder..::.ToString |
The StringBuilder class enables you to manipulate the characters in the string. The ToString method retrieves the text that is contained by theStringBuilder object. |
| StringWriter..::.Write
TextWriter..::.WriteLine
StringWriter..::.ToString |
The StringWriter class is useful when you have to append text to an output string. The StringWriterclass provides an internal buffer to which you can write text as if you were writing to a file. The Writeand WriteLine methods append text to the buffer. The ToString method retrieves the text that is contained by the StringWriter object. |
The buttons listing String class methods are actually RadioButton controls. The button appearance is obtained by setting the Appearance property to Button. The controls resemble buttons, but stay selected when clicked.
The buttons used to select the String class methods all call into the same event handler, HandleCheckedChanged. This procedure uses many Handles clauses. Inside the procedure, an If…Then statement uses the sender parameter to determine which button was selected and acts appropriately.
There is no way to float controls on top of a tab control, so that a single instance of a group of controls appears on each page. To provide that feature in this sample, selecting a page on the tab control sets the Parent property of a Panel control that contains all the “common” controls to be the selected page, like this:
pnlDemo.Parent = tabStringDemo.SelectedTab
To trigger a breakpoint so that you can walk through the StringBuilder and StringWriter code, the sample uses the Debugger..::.Break method. This method is called if the CheckBox control labeled Step through code is selected.