Feb 11

C# String Functions and Properties

Learn C#In C# programming, string is another kind of data type that represents Unicode Characters. It is the alias of System.String however, you can also write System.String instead of string. It is the sequence of character in which each character is a Unicode character.

There is no difference between string and String because string is the alias of System.String. Most of the developers get confused what to use between sting and String. Technically there is no difference between them and they can use any of them. However, you will have to use “using System” to use the String in C#. Another difference is String is a class name whereas string is a reserved keyword. You should always use string instead of String.

List of C# String Functions are given below:


String FunctionsDefinitions
Clone()Make clone of string.
CompareTo()Compare two strings and returns integer value as output. It returns 0 for true and 1 for false.
Contains()The C# Contains method checks whether specified character or string is exists or not in the string value.
EndsWith()This EndsWith Method checks whether specified character is the last character of string or not.
Equals()The Equals Method in C# compares two string and returns Boolean value as output.
GetHashCode()This method returns HashValue of specified string.
GetType()It returns the System.Type of current instance.
GetTypeCode()It returns the Stystem.TypeCode for class System.String.
IndexOf()Returns the index position of first occurrence of specified character.
ToLower()Converts String into lower case based on rules of the current culture.
ToUpper()Converts String into Upper case based on rules of the current culture.
Insert()Insert the string or character in the string at the specified position.
IsNormalized()This method checks whether this string is in Unicode normalization form C.
LastIndexOf()Returns the index position of last occurrence of specified character.
LengthIt is a string property that returns length of string.
Remove()This method deletes all the characters from beginning to specified index position.
Replace()This method replaces the character.
Split()This method splits the string based on specified value.
StartsWith()It checks whether the first character of string is same as specified character.
Substring()This method returns substring.
ToCharArray()Converts string into char array.
Trim()It removes extra whitespaces from beginning and ending of string.

Examples of C# String Function:



In this section you learned about different types of C sharp string function and properties like Clone(), CompareTo(), Contains(), EndsWith(), Equals(), GetHashCode(), GetType(), GetTypeCode(), IndexOf(), ToLower(), ToUpper(), Insert(), IsNormalized(), LastIndexOf(), Length, Remove(), Replace(), Split(), StartsWith(), Substring(), ToCharArray() and Trim(). These all functions are the essential thing that should be known by a good C# programmer

Permanent link to this article: http://zappmania.in/2014/02/11/c-string-functions-properties.htm

1 comment

    • Denese on September 25, 2014 at 5:19 pm
    • Reply

    I read a lot of interesting articles here. Probably you
    spend a lot of time writing, i know how to save you a lot of time, there is an online tool that creates high quality,
    SEO friendly posts in seconds, just type in google – laranitas
    free content source

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.