String class in C# (Methods and properties)
String Methods
- Substring(): Returns a new string that is a substring of the current string.
- Concat(): Concatenates two or more strings into a new string.
- Trim(): Removes leading and trailing white spaces from the string.
- Replace(): Replaces all occurrences of a specified character or string with another character or string.
- ToLower(): Converts all characters in the string to lowercase.
- ToUpper(): Converts all characters in the string to uppercase.
- Contains(): Returns a boolean indicating whether a specified substring is present in the string.
- IndexOf(): Returns the zero-based index of the first occurrence of a specified substring.
- Split(): Splits the string into an array of substrings based on a specified delimiter.
- StartsWith(): Returns a boolean indicating whether the string starts with a specified prefix.
- EndsWith(): Returns a boolean indicating whether the string ends with a specified suffix.
- Join(): Joins an array of strings into a single string using a specified separator.
- PadLeft(): Pads the string on the left with a specified character or space to a specified total length.
- PadRight(): Pads the string on the right with a specified character or space to a specified total length.
- Compare(): Compares two strings and returns an integer that indicates their relative position in the sort order.
- ToCharArray(): Converts the string to a character array.
Properties:
- Length: Gets the number of characters in the string.
- Chars[index]: Gets the character at the specified index in the string.
- IsNullOrEmpty: Gets a value indicating whether the string is null or an empty string.
- IsNullOrWhiteSpace: Gets a value indicating whether the string is null, empty, or consists only of white-space characters.
- First: Gets the first character of the string (C# 8.0 and later).
- Last: Gets the last character of the string (C# 8.0 and later).
- [int index]: Gets or sets the character at the specified index in the string.
- Chars: Gets an array containing the characters in the string.
- Original: Gets the original string before any transformations (C# 8.0 and later).
- Empty: Represents an empty string. This field is read-only.
Comments
Post a Comment