Modifying Fonts (An Example)

The following is an example application showing how we can modify a control’s Font property using other controls and components. We will use the techniques we have learned earlier to modify the font. Create a new Windows Forms Application and name it FontDemo. Read more

Using Fonts

What if you want to change or modify the font of a control in a windows application? The System.Drawing.Font class allows you to create fonts that you can use or assign to the Font properties of different controls or components. The following Read more

Extensible Markup Language

Extensible Markup Language (XML) allows you to store data in a text and structured format. It is widely used as a database alternative and for storing application configuration information. XML has a similar syntax with HTML so if you know Read more

Reading from a Text File

Reading data from a text file is almost similar to writing data to it. You create a  FileStream pointing to the file to be read. But instead of passing the stream to a  StreamWriter class, we used the  StreamReader class which contains methods for reading data Read more

C# System.IO.Path Class

The System.IO.Path class is a utility class that has methods for constructing paths of files and directories. Although you can simply use simple string concatenation and methods, using the Path class makes it easier for you when dealing with paths. The following table shows Read more

C# System.IO.DirectoryInfo Class

The System.IO.DirectoryInfo class represents a directory in your file system. Its capabilities are similar to the  System.IO.Directory class. You need to create an instance of DirectoryInfo class to make use of its properties and methods. DirectoryInfo directory = new DirectoryInfo(@”C:\Directory”); The constructor of Read more

C# System.IO.FileInfo Class

The System.IO.FileInfo class is quite similar to the System.IO.File class in that, they are used for the same purpose of manipulating a file. The difference is that FileInfo does not have static methods so you need to create an instance of it first. The created FileInfoobject represents Read more

C# System.IO.File Class

The System.IO.File class is a static class that exposes methods to manipulate an existing file in a directory. Such methods allow you to create, delete, open, move or copy a file.  As you can see, we need to import the System.IO namespace to be Read more

C# StringBuilder

The System.String class can use the + operator to concatenate two strings. But this is inefficient when concatenating two different strings. The reason is that String objects in .NET are immutable, that is, the value cannot be changed once it is assigned to the stringvariable. When you Read more

String Formatting

.NET provides you with ways to format the output of strings. You can use the String.Format to format your strings using different format specifiers. string str1 = “This”; string str2 = “That”; string str3 = String.Format(“{0} and {1}”, “This”, “That”); Console.WriteLine(str3); This Read more

Casing Strings

You can change the casing of a string. For example, a string composing of lowercase letters can be transformed into all caps. We use the ToUpper() and ToLower() instance methods which returns an uppercase or lowercase version of the string. string lowercase = “abc”; Read more

Searching Strings

Searching strings have been made easy thanks to the different methods provided by .NET. Let’s take a look at the different methods to find the occurrence of a particular string. The IndexOf and LastIndexOf methods find the index or position of a particular string Read more

Splitting Strings

If you want to split a string into multiples strings, you can use the Split method. Let’s take a look at the different overloads of the Splitmethod. The Split method returns a string array that contains the substrings inside each of its elements. The first Read more

Trim String

Sometimes, a user types unnecessary spaces that may cause certain errors. When accepting strings from a user, especially if the input came from a text box or similar controls, have a habit of trimming them first. .NET provides the Trim, TrimStart, and TrimEnd instance Read more

Inserting Strings

.NET provides you with the Insert instance method that allows you to insert strings into existing strings. For example, If you have a string “Hello World!”, you can insert the string “Happy ” in the middle to make it “Hello Happy World!”. Read more

String Concatenation

There are several ways of concatenating strings. Concatenating simply means combining multiple strings into one. In C#, the simplest way to concatenate strings is by using the + operator as shown below. string str1 = “Hello “; string str2 = “World”; string Read more

Comparing Strings

We can compare two strings for equality using several ways. For example, we can use the == operator to test if the two strings are equal. The == operator doesn’t compare their references, but their values even though strings are reference types. string str1 Read more

System.String Class

The string in C# is handled by the System.String class. Before you can create and use strings, you must import the System namespace. There are multiple ways to create a string. String str1; str1 = “An example of a string.”; Notice that a string Read more