String Manipulation in C#

String Manipulation is the most common part of many C# programs. Strings represent a sequence of characters. The easiest way to represent a sequence of characters in C# is by using a character array.

Example:

char[]name=new char[4];
name[0]='N';
name[1]='a';
name[2]='m';
name[3]='e';

C# supports two types of strings, namely:

1. Immutable strings: String objects are immutable, it means that we can’t modify the characters contained in them. However, since the string is an alias for the predefined [csharp]System.String[/csharp] class in the Common Language Runtime (CLR). There are many built-in operations available that work with strings. All operations produce a modified version of the string rather than modifying the string on which the method is called.

2. Mutable strings: These strings are modifiable and can be created using the [csharp]StringBuilder[/csharp] class.

Example:

StringBuilder srk1=new StringBuilder("Webeduclick");
StringBuilder srk2=new StringBuilder("");

Where the string object srk1 is created with an initial size of three characters and srk2 is created as an empty string. They can grow dynamically as more characters are added to them. They can grow either unbounded or up to a configurable maximum. Mutable strings are also known as Dynamic Strings.