38 lines
878 B
C#
38 lines
878 B
C#
namespace AdventOfCode;
|
|
|
|
public static class StringExtensions
|
|
{
|
|
public static IEnumerable<string> ReadAllLines(this StringReader reader)
|
|
{
|
|
while (reader.ReadLine() is { } line)
|
|
{
|
|
yield return line;
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<string> ReadAllLines(this string text)
|
|
{
|
|
return new StringReader(text).ReadAllLines();
|
|
}
|
|
|
|
public static char[,] AsCharGrid(this string text)
|
|
{
|
|
var lines = text.ReadAllLines().ToArray();
|
|
var lineCount = lines.Length;
|
|
var columnCount = lines[0].Length;
|
|
|
|
var grid = new char[lineCount, columnCount];
|
|
|
|
for (int i = 0; i < lineCount; i++)
|
|
{
|
|
var line = lines[i];
|
|
|
|
for (int j = 0; j < columnCount; j++)
|
|
{
|
|
grid[i, j] = line[j];
|
|
}
|
|
}
|
|
|
|
return grid;
|
|
}
|
|
} |