What is the best way to have the functionality of the StreamReader.ReadLine()
method, but with custom (String) delimiters?
I\'d like to do something like:>
public static String ReadUntil(this StreamReader streamReader, String delimiter)
{
StringBuilder stringBuilder = new StringBuilder();
while (!streamReader.EndOfStream)
{
stringBuilder.Append(value: (Char) streamReader.Read());
if (stringBuilder.ToString().EndsWith(value: delimiter))
{
stringBuilder.Remove(stringBuilder.Length - delimiter.Length, delimiter.Length);
break;
}
}
return stringBuilder.ToString();
}