如何用 ruby gsub 一个 unicode 0083 ?
我已经从 html.file 加载了一个字符串,并使用插件 ya2yaml: 将其写入 yaml 文件:
- title: 'What a wonderful day!'
body: ... # main contents here
并且我将通过 YAML::parse_file 方法加载 .yml 文件。
但是字符串中的“\n”会导致加载问题,所以我尝试将所有“\n”gsub到“”,但仍然存在问题,一个字符'0083'(我在终端中看到它)仍然断行,并导致加载问题:
in `load': syntax error on line 32, col 6: ` </strong><br>ok ' (ArgumentError)
from /home/croplio/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/syck.rb:178:in `parse'
from /home/croplio/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/syck.rb:203:in `block in parse_file'
from /home/croplio/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/syck.rb:202:in `open'
那么 yaml 或 char 0083 有什么问题吗?
或者我怎样才能避免这个问题?
I have loaded a string from a html.file, and I have writen it to a yaml file with the plugin ya2yaml:
- title: 'What a wonderful day!'
body: ... # main contents here
and I will load the .yml file by YAML::parse_file method.
but "\n" in the string will cause load problems, so I tried to gsub all "\n" to "", but there is still problems, a char '0083'(I see it in the terminal) still breaks the line, and cause loading problem:
in `load': syntax error on line 32, col 6: ` </strong><br>ok ' (ArgumentError)
from /home/croplio/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/syck.rb:178:in `parse'
from /home/croplio/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/syck.rb:203:in `block in parse_file'
from /home/croplio/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/syck.rb:202:in `open'
So what's wrong with the yaml or the char 0083?
or how can I avoid this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
0083 是一个 unicode 字符“NO BREAK HERE”。
我不知道 YAML::pars,但也许您可以将其切换为使用 unicode 或使用纯 ascii 代码。
0083 is a unicode character 'NO BREAK HERE'.
I don't know YAML::pars, but maybe you can switch it to use unicodes or use pure ascii codes.