Complete the code to check if the pattern exists in the text using IndexOf.
bool ContainsPattern(string text, string pattern) {
return text.[1](pattern) != -1;
}The IndexOf method returns the starting index of the pattern in the text or -1 if not found.
Complete the code to find the first occurrence index of the pattern in the text.
int FindPatternIndex(string text, string pattern) {
return text.[1](pattern);
}IndexOf returns the first index of the pattern or -1 if not found.
Fix the error in the code to correctly check if the pattern is at the start of the text.
bool StartsWithPattern(string text, string pattern) {
return text.[1](pattern);
}StartsWith checks if the text begins exactly with the pattern.
Fill both blanks to extract the substring from the first occurrence of the pattern to the end.
string ExtractFromPattern(string text, string pattern) {
int index = text.[1](pattern);
return index == -1 ? "" : text.[2](index);
}IndexOf finds the start index, and Substring extracts from that index to the end.
Fill all three blanks to create a dictionary of pattern counts in a list of texts.
Dictionary<string, int> CountPatternOccurrences(List<string> texts, string pattern) {
var counts = new Dictionary<string, int>();
foreach (var text in texts) {
int count = 0, index = 0;
while ((index = text.[1](pattern, index)) != -1) {
count++;
index += [2];
}
counts[[3]] = count;
}
return counts;
}Use IndexOf with a start index to find occurrences, increment index by pattern length to avoid overlap, and store count keyed by the text.
