I am trying to get to certain charcters in a file that is in UTF-16 format.
I know how many characters I want to skip. I am currently using the TextReader.ReadBlock command to read a temporary array of all of the characters I want to skip, but I believe that setting the position would be faster. I just do not how to determine the new position.
Any idea what would be the fastest way to skip to a position in a unicode file if you have how many characters that you want to skip?
It's not so easy to skip a block, that requires relative positioning.
If you can calculate the begiining of the next block (offset from the start of the file) it is doable:
        int nextPos = ...;
        reader.DiscardBufferedData();
        reader.BaseStream.Position = nextPos;
        line = reader.ReadLine();
You may have to tweak your calculation because UTF-16 file can have a BOM (2 leading bytes).
Considwring that this os UTF-16 and not UTF-8 (where character size can vary) you have 2 bytes per character. So to skip x characters you have to skip x*2 bytes.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论