6string
6string
1. What is a String?
- A string is a sequence of characters stored as text.
- In C, string is a built-in data type.
2. Declaring a String
- Syntax: string variableName;
- Example: string message;
3. Initializing a String
- You can assign a value directly:
Console.WriteLine(message[0]); // Outputs: H
5. String Concatenation
- Combine strings using + or String.Concat.
6. String Interpolation
- Use $ to embed variables into strings:
Console.WriteLine(message.Length);
8. Comparing Strings
- Use == or String.Equals.
9. Changing Case
- Convert to uppercase or lowercase:
10. Substring
- Extract part of a string:
4. Convert to Uppercase
5. Convert to Lowercase
8. Extract a Substring
string message = "Hello, World!";
string sub = message.Substring(7, 5);
Console.WriteLine(sub); // Outputs: World
9. Reverse a String