我是 RoR 的初學者。
這是原來的電話號碼 77123456999
我將其顯示為 77xxxxxx999
這是我的index.html.erb檔案代碼。
<tbody>
<% @users.each do |user| %>
<tr>
<td>
<%= user.username %>
</td>
<td>
<%= user.phone %>
</td>
<td>
<%= user.email %>
</td>
<td>
<%= user.state %>
</td>
</tr>
<% end %>
</tbody>
的值user.phone是 77123456999
How can I change is as I want?
uj5u.com熱心網友回復:
我會將 gsub 與正則運算式一起使用:
phone_number = " 77123456999"
phone_number.gsub(/(?<=\w{2})\w(?=\w{3})/, 'x')
#=> " 77xxxxxx999"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/416214.html
標籤:
上一篇:決議包含json字串的json
下一篇:十進制值被to_f截斷
