Socket question

  • Thread starter Thread starter Tony Caduto
  • Start date Start date
T

Tony Caduto

Does anyone know of a example on how to read \r\n (CRLF) delimited line
without using the streamreader class?

Thanks,
 
Tony Caduto said:
Does anyone know of a example on how to read \r\n (CRLF) delimited line
without using the streamreader class?

Well:

a) Why don't you want to use StreamReader?
b) What Encoding do you want to use?
c) What do you think you'll do differently to just reimplementing
StreamReader?
 
You mean something like this?

<code>
using System;

public class Test
{
public static void Main()
{
string text = "this is line1\r\nthis is line2 \r\nthis is line3\r\n";

int start = 0;
for(int i=0;i<text.Length-1;i++)
{
if (text=='\r' && text[i+1]=='\n')
{
int length = i-(start);
if (length>0)
{
string line = text.Substring(start, length);
Console.WriteLine(line);
}
start = i+2;
}
}
}
}
</code>


However, the ReadLine method of StreamReader (and StringReader) does pretty
much the same thing..

/Johan
 
Back
Top