我有一個練習,我必須做一個程式,以這種格式 "[email protected] "來編排一個從1到50的電子郵件串列
。我嘗試了幾種方法,我想我已經找到了正確的方法,但它只能轉換數字。在終端獲得的結果中,我得到了電子郵件地址和陣列中從1到50的數字。我希望它能逐一顯示郵件,并改變數字。 謝謝你。
。a = (1.50).to_a
puts "jean.dupont.#{a}@email.fr"
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
要逐一顯示電子郵件,你可以在range或array上迭代(使用each),并在電子郵件地址中插值每個數字
(1...50) 。 each { |n| puts "jean.dupont.#{n}@email.fr" }
=> jean.dupont.1@email.fr
=> jean.dupont.2@email.fr
=> jean.dupont.3@email.fr
=> jean.dupont.4@email.fr
=> jean.dupont.5@email.fr
=> ...
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/313817.html
標籤:
