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
精彩评论