Crlf ili carriage return line feed - znak za novi red ("\r\n")
Code:
using (FileStream fsSource = new FileStream(@"C:\text.txt",FileMode.Open, FileAccess.Read))
{
long numBytesToRead = fsSource.Length;
int nBytesRead = 0;
while (numBytesToRead > fsSource.Position)
{
byte[] c = new byte[1];
fsSource.Read(c, 0, 1);
char[] str = System.Text.ASCIIEncoding.ASCII.GetChars(c);
if (str[0] == '\r')
{
fsSource.Read(c, 0, 1);
str = System.Text.ASCIIEncoding.ASCII.GetChars(c);
if (str[0] == '\n')
{
long nPos = fsSource.Position; // pozicija novog reda ...
}
}
}
fsSource.Close();
}
Ovaj primer vazi samo za fajlove sa Asci encodingom ...
ako budes hteoa da napravis univerzalnu rutinu i za Unicode i za Asci ..
moraces da detektujes encoding u samom fajlu da bi znao velicinu buffera
byte[] c = new byte[1]; za asci
byte[] c = new byte[2]; za unicode
kao i razlicite metode :
System.Text.ASCIIEncoding.ASCII.GetChars(c);
System.Text.UnicodeEncoding.Unicode.GetChars(c);
itd ..
U .NET frejmvorku postoje nacini za detektovanje :
Code:
StreamReader sr = new StreamReader(fsSource, true);
Encoding enc = sr.CurrentEncoding;
Medjutim ovaj metod nije pouzdan i ne detektuje kako treba
stoga probaj odavde da izvuces trenutni enkoding za fajl ..
http://www.west-wind.com/WebLog/posts/197245.aspx
Viva lollapalooza