Mental Model
A string is a sequence of characters you can look at one by one from start to end.
Analogy: Imagine reading a sentence letter by letter with your finger pointing to each character in order.
S -> t -> r -> i -> n -> g -> null ā
S -> t -> r -> i -> n -> g -> null ā
"C" -> "o" -> "d" -> "e" -> null ā
"C" -> "o" -> "d" -> "e" -> null ā
"C" -> "o" -> "d" -> "e" -> null
ā"C" -> "o" -> "d" -> "e" -> null
ā"C" -> "o" -> "d" -> "e" -> null
ā"C" -> "o" -> "d" -> "e" -> null Output: C o d e
using System; class Program { static void TraverseString(string input) { for (int i = 0; i < input.Length; i++) { Console.WriteLine(input[i]); // print current character } } static void Main() { string test = "Code"; TraverseString(test); } }
for (int i = 0; i < input.Length; i++)Console.WriteLine(input[i]); // print current characterfor (int i = 0; i < input.Length; i++)
for (int i = 0; i < input.Length; i++)
str[2] return when string str = "hello";?str in C#?string s = "code";
for (int i = 0; i < s.Length; i++)
{
if (i % 2 == 0)
Console.Write(s[i]);
}string text = "example";
for (int i = 0; i <= text.Length; i++)
{
Console.Write(text[i]);
}input, which code snippet correctly counts how many vowels (a, e, i, o, u) it contains?Pass the test and this pattern moves unknown