diff --git a/src/libraries/System.Console/src/System/TermInfo.cs b/src/libraries/System.Console/src/System/TermInfo.cs index 0241e77bf43fca..32e4aa1cbfcab5 100644 --- a/src/libraries/System.Console/src/System/TermInfo.cs +++ b/src/libraries/System.Console/src/System/TermInfo.cs @@ -161,20 +161,12 @@ private static string EvaluateInternal( // (with a ':' used in front of flags to help differentiate from binary operations, as flags can // include '-' and '+'). While above we've special-cased common usage (e.g. %d, %s), // for more complicated expressions we delegate to printf. - int printfEnd = pos; - for (; printfEnd < format.Length; printfEnd++) // find the end of the printf format string - { - char ec = format[printfEnd]; - if (ec == 'd' || ec == 'o' || ec == 'x' || ec == 'X' || ec == 's') - { - break; - } - } - if (printfEnd >= format.Length) + int printfEnd = format.AsSpan(pos).IndexOfAny("doxXs"); // find the end of the printf format string + if (printfEnd < 0) { throw new InvalidOperationException(SR.IO_TermInfoInvalid); } - string printfFormat = format.Substring(pos - 1, printfEnd - pos + 2); // extract the format string + string printfFormat = format.Substring(pos - 1, printfEnd + 2); // extract the format string if (printfFormat.Length > 1 && printfFormat[1] == ':') { printfFormat = printfFormat.Remove(1, 1);