mirror of
https://github.com/AlexMacocian/SystemExtensions.git
synced 2026-07-18 15:29:30 +00:00
Read until extension.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace System.Extensions
|
||||
{
|
||||
@@ -36,5 +37,31 @@ namespace System.Extensions
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return stream;
|
||||
}
|
||||
|
||||
public static string ReadUntil(this StreamReader sr, string delim)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
bool found = false;
|
||||
|
||||
while (!found && !sr.EndOfStream)
|
||||
{
|
||||
for (int i = 0; i < delim.Length; i++)
|
||||
{
|
||||
char c = (char)sr.Read();
|
||||
sb.Append(c);
|
||||
|
||||
if (c != delim[i])
|
||||
break;
|
||||
|
||||
if (i == delim.Length - 1)
|
||||
{
|
||||
sb.Remove(sb.Length - delim.Length, delim.Length);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user