public static int NormalizeStringIndex(string s, int index) { return index < 0 ? Math.Max(0, index + s.Length) : Math.Min(index, s.Length); }