.Net file writing and string splitting issues
Posted
by
sagar
on Stack Overflow
See other posts from Stack Overflow
or by sagar
Published on 2012-12-07T04:54:55Z
Indexed on
2012/12/07
5:03 UTC
Read the original article
Hit count: 111
I have a requirement where the file should be split using a given character. Default splitting options are CRLF and LF In both these cases I am splitting the line by \r\n and \r respectively.
Also I have requirement where any size of file should be processed. (Processing is basically inserting the given string in a file at given position).
For this I am reading the file in chunk of 1024 bytes.
Then I am applying the string.Split() method. Split() method gives options for ignoring white spaces and none.
I have to add back these line break characters to the line. for this I am using a binary writer and I am writing the byte array to the new file. Issue:-
1) When line break is CRLF, and the split option is NONE, while spaces are also added in the splitted array. Second option is given (to ignore white spaces) CRLF works properly.
2)Bit ignoring white space option creates other problems, as I am reading the file byte by byte I can't ignore a white space.
3)When line break characters are other than default(e.g. '|', a null value is prepended to the resulting line.
Can anybody give solution to my issues?
© Stack Overflow or respective owner