【源码】读取任何(文本)文件UTF8或ANSI

在这里插入图片描述

如果你想用Matlab读取一个(文本)文件,你需要知道它是什么编码:UTF-8(“现代”标准)或ANSI(US-ASCII,旧的标准)。

If you want to read a (text) file with Matlab, you need to know what encoding it is: UTF-8 (the ‘modern’ standard) or ANSI (US-ASCII, the ‘old’ standard).

如果你想自动读取文件,你不一定知道你必须猜测编码形式。

If you have files you want to read automatically, where you don’t necessarily know the encoding you would have to guess.

有时会导致奇怪的文本,您在3或4个步骤后才会注意到。

This will sometimes result in strange text that you only notice 3 or 4 steps later.

本代码通过提供一种读取文件的单一方式来解决这个问题。

This submission takes care of that problem by providing a single way of reading a file.

保留前导和尾随空格,保留空行,并且可以处理UTF-8文件和ANSI文件。

It preserves leading and trailing spaces, it preserves empty lines, and it can handle both UTF-8 files and ANSI files.

请注意,虽然编码应该以特殊的前导位指定,但是用Matlab无法读取。

Note that although the encoding should be specified in a special leading bit, it is not possible to read this with Matlab.

因此,有可能使用错误的编码读取文件,尽管这种情况非常罕见。

It is therefore possible that a file is read with the wrong encoding, although this should be a very rare occurrence.

也可以将文件名作为URL输入。

It is also possible to enter the file name as a URL.

在这种情况下,此函数将把文件下载到临时目录中,读取后删除它。

In that case this function will download the file to the temporary directory, read it, and delete it.

Licence: CC by-nc-sa 4.0

更多精彩文章请关注公众号:在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值