C# provides several methods for string manipulation, which can be quite handy in various programming scenarios. Here are some common string manipulation methods:
String.Concat
or +
operator: Combines multiple strings.
Substring(int startIndex)
and Substring(int startIndex, int length)
: Extracts a portion of the string.
Replace(string oldValue, string newValue)
: Replaces occurrences of a specified string in the input string.
Trim()
, TrimStart()
, TrimEnd()
: Removes whitespace from the beginning and/or end of the string.
ToUpper()
and ToLower()
: Converts all characters in the string to uppercase or lowercase.
Split(char separator)
: Splits the string into an array of substrings based on a delimiter.
Join(string separator, string[] value)
: Combines an array of strings into a single string with a delimiter.
Contains(string value)
: Checks if the string contains a specified substring.
IndexOf(char value)
and LastIndexOf(char value)
: Returns the index of the first and last occurrence of a character in the string.
StartsWith(string value)
and EndsWith(string value)
: Checks if the string starts or ends with a specified substring.
String.Format(format, args)
: Inserts arguments into a string with placeholders.
These are just a few examples of the many string manipulation methods available in C#. If you need more details or specific use cases, feel free to ask!