Aquí es un analizador sencilla utilicé cuando sea necesario (por lo general si el streaming no es una suma que acaba de leer y .split hace el trabajo), no muy optimizado, pero debería funcionar bien:
(que es más de una división como método - y más notas abajo)
public static IEnumerable<string> Split(this Stream stream, string delimiter, StringSplitOptions options)
{
var buffer = new char[_bufffer_len];
StringBuilder output = new StringBuilder();
int read;
using (var reader = new StreamReader(stream))
{
do
{
read = reader.ReadBlock(buffer, 0, buffer.Length);
output.Append(buffer, 0, read);
var text = output.ToString();
int id = 0, total = 0;
while ((id = text.IndexOf(delimiter, id)) >= 0)
{
var line = text.Substring(total, id - total);
id += delimiter.Length;
if (options != StringSplitOptions.RemoveEmptyEntries || line != string.Empty)
yield return line;
total = id;
}
output.Remove(0, total);
}
while (read == buffer.Length);
}
if (options != StringSplitOptions.RemoveEmptyEntries || output.Length > 0)
yield return output.ToString();
}
... y simplemente pueden cambiar a char delimitadores solo si es necesario reemplazar el
while ((id = text.IndexOf(delimiter, id)) >= 0)
... con
while ((id = text.IndexOfAny(delimiters, id)) >= 0)
(y id++
en lugar de id+=
y una firma this Stream stream, StringSplitOptions options, params char[] delimiters
)
... también elimina vacío, etc.
creo que sirve
Por qué no usar ReadLine() y luego buscar delimitador en cadena? –
Mediante el uso de 'Peek()' y 'StringBuilder' que está básicamente replicar lo' ReadLine() '' hacer dentro StreamReader' ... por lo que me parece extraño que sea tan lento; ¿puedes publicar lo que has intentado? – digEmAll
ineficiente? ¿Qué tan ineficiente? Es el rendimiento que carece notablemente? –