But as you've noted this solution is "slow" :-) And even here, beware of the end-of-line, that could be two characters ( \r\n), while "logically" they are a single character (if you are at the beginning of a line in notepad and press a single backspace, it will erase completely \r\n). The simplest solution is to load the whole file in memory inside a string (or similar), modify it, and then re-write it to disk. net char, corresponding to 25 bytes in UTF-8), but we will ignore this problem Note that more complex emojis (like □□□ family ) are composed by multiple single emojis (4 unicode codepoints, corresponding to 11. So a single \b would probably need to erase one or two char (and between 1 and 4 bytes in UTF-8), depending on what it finds. This makes reading with StreamReader and then doing corrections "in place" with StreamWriter quite complex.Įven if we had a StreamReaderWriter, it would be a little difficult.NET works with UTF-16 chars, so that many Unicode characters (emoji like □ grinning face for example) are composed of two char. Sadly they are separate (one is only read, one is only write), and sadly they pre-buffer, so that the FileStream.Position doesn't correspond to the currently "read" character in StreamReader. StreamReader and StreamWriter can be "connected" to a FileStream. You see your beautiful nick sɐunıɔןɐqɐp? It clearly needs some encoding :-) Sadly it doesn't know about encoding and it works in bytes. Doing it "correctly" in the "most general case" is very very, very difficult.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |