简体   繁体   English

强制将文字ASCII字符转换为字符串

[英]Force Literal ASCII character into string

I'm generating the following array for use in a JS charting library: 我正在生成以下数组,以用于JS图表库:

['DE',   50], ['GB',   9], ['IE',   2]

However, I need to force in the literal apostrophe so that the JS library renders the chart correctly. 但是,我需要强制使用文字撇号,以便JS库正确显示图表。 ie ['DE', 50], ['GB', 9], ['IE', 2] 即['DE',50],['GB',9],['IE',2]

I'm sure this is simple, but I just keep ending up with the ASCII codes. 我敢肯定这很简单,但我一直以ASCII码结尾。

My Ruby code is 我的Ruby代码是

@product.sales_data.map { |territory,sales| "['" << territory << "',   " << sales.to_s << "]" }.join(", ")

This works fine in ruby 2.0.0 at least 至少在ruby 2.0.0中工作正常

sales_data = [['DE', 50], ['GB', 9], ['IE', 2]]
sales_data.map { |territory, sales| "['" << territory << "', " << sales.to_s << "]"}.join(", ")

or alternatively 或者

sales_data.map { |territory, sales| "['#{territory}', #{sales}]" }.join(", ")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将字符串中的ASCII字符转换为jQuery中的字符? - How to convert ascii character in string to character in jquery? 在jmeter中使用转义字符时的Java强制文字 - java force literal when using escape character in jmeter 删除字符串中的非ascii字符 - Remove non-ascii character in string Javascript - 替换字符串文字中的转义字符 - Javascript - Replacing the escape character in a string literal 检查字符串中字符的ASCII码值是否大于或小于前一个字符的ASCII码值-JavaScript - Check if ASCII Code Value Of Character In String Is Greater Than or Less Than ASCII Code Value of Previous Character - JavaScript ES6:错误字符转义序列创建ASCII字符串 - ES6: Bad character escape sequence creating ASCII string 对于字符串中的每个字母,请打印其ASCII字符表示形式 - For every letter in a string, print its ascii character representation 字符转义:从Python字符串文字到JSON再到HTML - character escaping: from Python string literal to JSON and then to HTML JSON 中字符串文字中的错误控制字符位于位置 197 错误 - Bad control character in string literal in JSON at position 197 error JSON.parse:字符串文字中的错误控制字符 - JSON.parse : Bad control character in string literal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM