C#- useful function for string reference type


String Reference type method:

bool b = a.Contains (‘x’); / / Contains () to determine whether this word contain certain string. return bool value type.

bool b = a.StartsWith (” x “); // StartsWith () check if the string starts with the character x. return Boolean value type.

bool b = a.EndsWith (” x “); // EndsWith () check if the string ends with the character x. return Boolean value type.

bool b = a.Equals ( “xx”); // Equals () to determine whether two strings are the same.

int b = a.IndexOf (“x”); // IndexOf () return the index of the char in the string.

int b = a.LastIndexOf (“x”) ; // LastIndexOF () return the last index of char in the string.

string b = a.Insert(int, “x”); insert the char at the index of you want.

bool b = string.IsNullOrEmpty (x); // IsNullOrEmpty () will check whether the string is null or empty. It will return a Boolean value.

string b=a.Remove(1,10); //Remove() delete the string from index 1 to 10 and return the rest to string b.

string [] strs = a.Split (‘x’); // split()

string strs = a.Substring (int, int); / / Substring () is also used to split the string with the index starting with first parameter and ending with the second parameter.(return string)

string str = strs.ToLower() // The ToLower () convert uppercase to lowercase

string str = strs.ToUpper = (); // the ToUpper () convert lowercase to uppercase.

string str = strs.Trim (); // Trim () clears the space on both sides of the string

Social Media


Categories



All Posts



Contact Info