How it works
A string search returns a position, not merely a yes-or-no answer. IndexOf returns a zero-based index when it finds the requested text and negative one when it does not. Keeping that distinction visible lets a parser decide whether a separator exists before attempting to take a substring. The absence of a separator should be part of the format contract.
Comparison rules belong to that contract too. Human-language sorting and matching can depend on culture. Machine tokens, protocol labels, and simple structured keys usually need ordinal comparison, optionally ignoring case when the format says case is irrelevant. Specify the comparison explicitly so that the behavior is understandable from the code and does not depend on the user's language settings.
Walk through the example. The program finds the colon in a small key-value line and slices the text around that position. It compares the key using ordinal case-insensitive rules, so the uppercase input matches the expected token. A separate search for a missing equals sign prints negative one. The delimiter check occurs before the slicing operation, which keeps the successful example's assumptions visible.
Watch the boundary. Substring and range operations do not understand a data format automatically. Searching for one colon is not enough to parse every possible escaped or quoted format. If the format permits delimiters inside values, write down those rules or use an appropriate parser. Also avoid lowercasing both values as a substitute for choosing the right comparison operation.
Practice independently. Write a parser for simple name=value lines that splits only at the first equals sign. Decide whether blank names are valid and whether whitespace is trimmed. Test a missing separator, an empty value, mixed-case keys, and a value containing a second equals sign. Return a failure result for malformed input instead of allowing an invalid slice to throw unexpectedly.
A working example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
string line = "MODE:fast";
int separator = line.IndexOf(':');
if (separator >= 0)
{
string key = line[..separator];
string value = line[(separator + 1)..];
Console.WriteLine(key.Equals("mode", StringComparison.OrdinalIgnoreCase));
Console.WriteLine(value);
}
Console.WriteLine(line.IndexOf('='));
Expected output
True fast -1
Check for a missing delimiter before slicing, and choose ordinal rules for machine tokens.