Reading UTF-8 text files with ReadList

后端 未结 2 454
攒了一身酷
攒了一身酷 2021-01-13 03:25

Is it possible to use ReadList to read UTF-8 (or any other) encoded text files using ReadList[..., Word], or is it ASCII-only? If it\'s ASCII-only

2条回答
  •  伪装坚强ぢ
    2021-01-13 04:04

    This seems to work

    FromCharacterCode[ToCharacterCode[ReadList["raw.php.txt", Word]], "UTF-8"]
    

    The timings I get for the linked test file are

    FromCharacterCode[ToCharacterCode[ReadList["test.txt", Word]], "UTF-8"]); // Timing
    
    (* ==> {0.000195, Null} *)
    
    Import["test.txt", "Text"]; // Timing
    
    (* ==> {0.01784, Null} *)
    

提交回复
热议问题