2012-08-14 69 views

回答

5

你可以把Unicode字符在那裏。

str = "\u2022" + " hello world" 
+0

在1.9.3的IRB中測試過它,它不起作用,它只是返回字符串文字'「\ u2022」'。想法? – lyonsinbeta 2012-08-14 15:57:17

+0

我正在使用Ruby 2.1.6p336。這種方法適用於我。 – Tanoro 2018-01-04 17:39:37

1

對我的作品(紅寶石1.9.3)

str = "•" + " hello world" 
str # => "• hello world" 
1

不要使用ASCII字符串–但你使用的是什麼版本的Ruby你沒有狀態。如果您使用的是1.8,您還可以使用Unicode字符"\u2022",或者查看下面的引導中的其他選項。

在1.9這應該工作正常。您也可以使用encode和/或force_encoding強制使用UTF-8。

Ruby 1.9 Encodings Primer