开发者

How To Convert Arabic Number Ascii Code to String in ROR?

I want to convert my English Numbers Pager to an Arabic one, I had something like

<% @engnum = "0123456789" %>
<% @arabnu开发者_JAVA技巧m = "٠١٢٣٤٥٦٧٨٩" %>

<%= (@pagenumber).to_s.gsub(/./) {|s| @arabnum[@engnum.index(s)]} %>

But this shows the ascii number not the actual number i need

Any idea how to show the actual string (Number) Remember that it's arabic numbers and @arabnum[@engnum.index(s),1] didn't work

Thanks in advance


#encoding: utf-8
pagenumber = "512"
p pagenumber.tr("0123456789","٠١٢٣٤٥٦٧٨٩") 
#=>  "٥١٢"


You should try

@pagenumber.to_s.gsub(/./) {|s| @arabnum[i=@engnum.index(s),i]}

For more information about this you should read http://ruby-doc.org/core/classes/String.html#M000771

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜