Skip to main content

Posts

Showing posts from June, 2020

StringBuilder in C# with Example

StringBuilder in C# with Example StringBuilder  is a class that is useful to represent a mutable string of characters and it is an object of  System.Text  namespace.   Like string we can use a  StringBuilder  to create variables to hold any kind of text which is a sequential collection of characters.   In C#, both string and StringBuilder will represent a sequence of characters and perform the same kind of operations but the only difference is strings are  immutable  and StringBuilder is  mutable .   Generally, the string object cannot be modified once it created. If any changes made to the string object like add or modify an existing value, then it will simply discard the old instance in memory and create a new instance to hold the new value. In case, if we are doing repeated modifications on the string object, then it will affect the performance of appl...

Remove Method of string in C# Explained

Remove Method of string in C# The  string   Remove   method  is used to delete characters in the  string  starting from the specified position and continues to the end of the  string .   In case, if we want to delete a particular length of substring, then we need to specify the starting position and length of characters to delete from the given  string .   Remove Method Syntax Following is the syntax for defining a  string   Remove   method  to remove characters starting from the defined position in a given  string .   public string Remove( int startIndex) public string Remove( int startIndex, int length)   Given the above syntaxes, the first syntax is used to delete all the characters in the  string , starting from the defined position ( startIndex ) and the second syntax is used to delete particular length of a  substring  by defining the starting position a...

Trim method of string in C# Explained

Trim method of string in C# The string  Trim   method  is used to remove all trailing and leading whitespace characters from the specified  string   object.   By using the  Trim()   method , we can also remove all occurrences of specified characters from the start and end of the current  string .   Trim Method Syntax Following is the syntax of defining a string  Trim   method  to remove all leading and trailing whitespaces or specified characters from the  string   object.   public string Trim() public string Trim( char [] trimChars)   From the above syntaxes, the first syntax is used to remove all whitespaces from the starting and end of the specified  string   and it won’t take any parameters.   The second syntax is used to remove trailing and leading occurrences of specified characters in an array from the current  string   object.   Tri...