String Class (String)

Provides basic string manipulation.

Overview

The String class represents text. It is the most commonly used class in the .NET Framework. The class provides a wide range of methods and properties for manipulating strings.

Properties

The String class provides a variety of properties that can be used to access and modify string values.

Property Description Example
Length The number of characters in the string. string myString = "Hello"; int length = myString.Length;
ToLower() Returns a new string with all characters converted to lowercase. string upperCaseString = myString.ToLower();
ToUpper() Returns a new string with all characters converted to uppercase. string lowerCaseString = myString.ToUpper();

Methods

The String class provides a variety of methods for manipulating strings. Some common methods include:

Examples

Concatenating Strings

You can concatenate strings using the + operator or the Concatenate() method.

string firstName = "John";
        string lastName = "Doe";
        string fullName = firstName + " " + lastName;
        Console.WriteLine(fullName); // Output: John Doe
        

Checking if a String Starts with a Specific Prefix

The StartsWith() method checks if a string starts with a specific prefix.

string myString = "Hello World";
        bool startsWithHello = myString.StartsWith("Hello");
        Console.WriteLine(startsWithHello); // Output: True