Reputation: 21
I want to convert my English Numbers Pager to an Arabic one, I had something like
<% @engnum = "0123456789" %>
<% @arabnum = "٠١٢٣٤٥٦٧٨٩" %>
<%= (@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
Upvotes: 2
Views: 1613
Reputation: 80065
#encoding: utf-8
pagenumber = "512"
p pagenumber.tr("0123456789","٠١٢٣٤٥٦٧٨٩")
#=> "٥١٢"
Upvotes: 4
Reputation: 18175
You should try
@pagenumber.to_s.gsub(/./) {|s| @arabnum[[email protected](s),i]}
For more information about this you should read http://ruby-doc.org/core/classes/String.html#M000771
Upvotes: 0