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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top