我有一个具有ascii特殊字符的字符串,我希望将这些字符转换为相应的unicode字符。例如,下面是字符串
A “razor” is a rule of thumb that simplifies decision.. \nWe’re in a post-content age. In the past,\nhealthier, wealthier life: • Toxic relationships • Comparisons • Inactivity • Complaints • Instant gratification • Overthinking • Crazy “what if” fears 期望输出
A "razor" is a rule of thumb that simplifies decision.. \nWe're in a post-content age. In the past,\nhealthier, wealthier life: • Toxic relationships • Comparisons • Inactivity • Complaints • Instant gratification • Overthinking • Crazy "what if" fears我能得到的最好的结果是使用单模码 gem。将上面的字符串转换为
"A \"razor\" is a rule of thumb that simplifies decision..\nWe're in a post-content age. In the past,\nhealthier, wealthier life: * Toxic relationships * Comparisons * Inactivity * Complaints * Instant gratification * Overthinking * Crazy \"what if\" fears "这种方法的问题是,如果字符串是用另一种语言编写的,那么unidecode to_ascii方法将转换该字符。
发布于 2022-09-14 03:08:41
所以,您要问的不是ascii,而是ASNI,也称为windows-1252,我建议您查看一下Windows-1252 wiki,因为它有一个表,表上标记了Unicode代码点。从ansi到unicode没有简单快捷的转换方法,在wiki页面中使用表的方式是在unicode中找到并替换了相同的字形。
ansi、asci和unicode的一个特点是,头128个字符在它们之间都是相同的。
就我个人而言,我只想做一个查找表,以及ruby如何使用以下方法来处理unicode字符串:"\u“,在这里,您用代码点的十六进制值替换它,因此对于项目点:”·“将转换为:”\u 2022“,如果您需要查找unicode代码点,我建议:unicodeplus.com,因为它甚至为几种不同的编程语言的每个代码点提供转义序列。
https://stackoverflow.com/questions/73710769
复制相似问题