字符编码问题
我最近正在编辑一个 Unicode 编码的文本文件,其中还包含泰语字符(以及“普通”字符)。由于某种原因,在每个泰语字符序列之后,都会出现一个新行。
在用 C 进行了一些修改之后,尝试删除所有换行符,我启动了 vim 来检查文件。显然,在每个泰语字符序列之后,都会出现一个“^M”字符串(不带引号)。
为什么会发生这种情况,“^M”是什么?我发现我可以通过删除泰语字符串中的最后三个字符来解决问题,但肯定必须有一种更优雅的方法来解决这个问题......
I was recently editing a Unicode-encoded text file that also includes Thai characters (alongside "normal" characters). For some reason, after each sequence of Thai characters, a new line appeared.
After some mucking around with C, trying to remove all newline characters, I fired up vim to inspect the file. Apparently, after each Thai character sequence, there appears a "^M" string (without quotes).
Why is this happening, and what's that "^M"? I've found that I can fix the problem by removing the last three characters from the Thai string, but there surely must be a more elegant way to fix this ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这与文件中包含一些泰语字符这一事实无关。
^M
('carrot M')是 Microsoft (DOS) 回车符的表示。 Dos2unix 文件,在 vim 中编辑之前删除这些文件。This has nothing to do with the fact that you have some Thai characters in the file. The
^M
('carrot M') is the representation of a Microsoft (DOS) carriage return. Dos2unix the file to get rid of these before editing it in vim.