Iterating Over Strings
Strings as char sequences.
Strings Are Sequences
A string is a sequence of char values in order.
This means you can loop over a string and look at one character at a time. Iterating is how you inspect, count, or transform the characters in text.
string text = "Hello";
// 'H', 'e', 'l', 'l', 'o'The Length Property
Every string has a Length property that tells you how many characters it holds.
You will use Length to control loops and to know the last valid index, which is always Length - 1.
class Program
{
static void Main()
{
string text = "Hello";
System.Console.WriteLine(text.Length);
}
}All lessons in this course
- The char Type
- Char Helper Methods
- Iterating Over Strings
- Building Strings