System.String
The String
class represents immutable text as a sequence of Unicode characters.
Namespace
System
Assembly
System.Runtime.dll
Inheritance
Object → String
Constructors
public String(char[] value);
public String(char c, int count);
public String(char[] value, int startIndex, int length);
public String(ReadOnlySpan<char> value);
public String(string? value);
Properties
Name | Type | Description |
---|---|---|
Length | int | Gets the number of characters in the current string. |
Chars[int index] | char | Gets the character at the specified position. |
Methods
Manipulation
static string Concat(params string?[]? values)
string Substring(int startIndex)
string Substring(int startIndex, int length)
string Replace(string oldValue, string? newValue)
string ToUpper()
string ToLower()
string Trim()
string[] Split(params char[] separator)
Comparison
int CompareTo(string? strB)
bool Equals(string? value)
- static
bool Equals(string? a, string? b)
- static
bool IsNullOrEmpty(string? value)
- static
bool IsNullOrWhiteSpace(string? value)
Examples
// Concatenating strings
string first = "Hello";
string second = "World";
string combined = string.Concat(first, " ", second); // "Hello World"
// Using interpolation
int year = 2025;
string message = $"The year is {year}."; // "The year is 2025."
// Splitting and joining
string csv = "apple,banana,cherry";
string[] fruits = csv.Split(',');
string rejoined = string.Join(" | ", fruits); // "apple | banana | cherry"