Q:

Determine 1-based line and column number given absolute 0-based index of string (C#)

In C#, given a string and a 0-based index value, how can I determine the 1-based line and column numbers?
This should work for strings that come from various platforms with different line ending conventions.
Edit: I posted an answer that works in a variety of scenarios and is concise. I'm open to other answers that can prove they are either faster and/or correct using examples with varying line endings and number of lines.

A:

Here is a solution that determines the overall # of line breaks in the source string, making the logic more concise:
public (int line, int column) GetLocation(string value, int position)
{
    var line = 1;
    var column = position + 1;

    var matches = new Regex("\r\n?|\n").Matches(value);
    for (var i = 0; i < matches.Count; i++)
    {
        var match = matches[i];
        if (match.Index >= position)
        {
            break;
        }

        line += 1;
        column = position + 1 - (match.Index + match.Length);
    }

    return (line, column);
}

