Tag: ascii

不兼容的字符编码:ASCII-8BIT和UTF-8,同时在rails中使用javascript

我试图在我的rails 3应用程序版本1.9.3中使用javascript。 当我包含此行%= javascript_include_tag “application” %>我收到以下错误: Encoding::CompatibilityError in Products#index incompatible character encodings: ASCII-8BIT and UTF-8 Extracted source (around line #9): 6: 7: 8: 9: 10: 11:

为什么从ASCII-8BIT到UTF-8会出现字符串编码问题“\ xE2”?

我正在尝试从电子邮件下载PDF并将内容写入文件。 出于某种原因,我收到此错误: An Encoding::UndefinedConversionError occurred in attachments#inbound: “\xE2” from ASCII-8BIT to UTF-8 app/controllers/api/attachments_controller.rb:70:in `write’ 这是我的代码: def inbound if Rails.env.production? or Rails.env.staging? email = Postmark::Mitt.new(request.body.read) else email = Postmark::Mitt.new(File.binread “#{Rails.root}/app/temp_pdfs/email.json”) end if email.attachments.count == 0 # notify aidin that we got an inbound email with no attachments respond_to do |format| format.json { head :no_content } end […]

如何使用Ruby 1.9检测字符串是否仅包含拉丁符号?

我需要检测一些字符串是否包含非拉丁字母表中的符号。 数字和特殊符号如- , _ , +都很好。 我需要知道是否有任何非拉丁符号。 例如: “123sdjjsf-4KSD”.just_latin? 应该回归true 。 “12333ыц4–sdf”.just_latin? 应该返回false 。

将带有hexASCII码的字符串转换为字符

我有一个包含ASCII字符的hex代码值的字符串,例如”666f6f626172″ 。 我想将它转换为相应的字符串( “foobar” )。 这很有效但很难看: “666f6f626172”.scan(/../).map(&:hex).map(&:chr).join # => “foobar” 有更好(更简洁)的方式吗? unpack可能会有所帮助吗?

Ruby错误UTF-8到ASCII

我在Centos 5.5上安装了Ruby 1.9.2。 每次我安装一个gem,我都会收到错误 ERROR: While generating documentation for (gem) … MESSAGE: U+2018 from UTF-8 to US-ASCII … RDOC args: lib History.txt README.txt gem仍然安装好,但有些事我不能做。 比如使用SproutCore。 我得到了这个小gem(双关语)。 sc-init xxxx ~ Created directory at xxxx FATAL ~ invalid byte sequence in US-ASCII 任何人都知道发生了什么,以及如何解决它? 谷歌对此没什么帮助。

Ruby:从字符串到ascii的字符

这个维基页面提供了如何将单个字符转换为ascii的一般概念http://en.wikibooks.org/wiki/Ruby_Programming/ASCII 但是说如果我有一个字符串并且我想从中获取每个字符的ascii,我需要做什么? “string”.each_byte do |c| $char = c.chr $ascii = ?char puts $ascii end 它不起作用,因为它对行$ ascii =?char不满意 syntax error, unexpected ‘?’ $ascii = ?char ^