public static SplitLines ( this instance, int numberOfLines ) : string[] | ||
instance | this | |
numberOfLines | int | |
리턴 | string[] |
public static string[] SplitLines(this string instance, int numberOfLines = 0)
{
if (numberOfLines < 0) throw new ArgumentOutOfRangeException(nameof(numberOfLines), "Number of Lines must be a positive integer.");
if (instance == null) return null;
string[] split = instance.Split('\r', '\n');
IEnumerable<string> query = split.Where(l => l.Length > 0);
if (numberOfLines > 0)
{
query = query.Take(numberOfLines);
}
return query.ToArray();
}