Background and motivation
Some APIs return Range instances to specify subsets. You can use such a Range with a string like str[range] to get the substring, but that allocates a string. MemoryExtensions exposes AsSpan methods that take Ranges, but only for T[] and ArraySegment<T>, not string. It does have a Range-based string extension, but only AsMemory.
API Proposal
namespace System;
public static class MemoryExtensions
{
public static ReadOnlySpan<char> AsSpan(this string? text, Range range);
}
API Usage
ReadOnlySpan<char> span = string.AsSpan(range);
Alternative Designs
No response
Risks
No response