Code inspection: Replace 'Substring' with range indexer
This inspection reports Substring(...) calls that can be replaced with the C# range indexer syntax. It applies when the same substring boundaries can be expressed as a range, for example [..5], [1..], or [^3..].
Example
string text = "Hello world";
var prefix = text.Substring(0, 5);
var rest = text.Substring(6);
string text = "Hello world";
var prefix = text[..5];
var rest = text[6..];
Quick-fix
Range syntax is more compact and makes it easier to see which part of the string is being selected.
30 March 2026