ruby 學習 -- string --1

來源:互聯網
上載者:User

標籤:

# definefrench_string = "il \xc3\xa9tait une fois"long_string = <<EOFHere is a long stringWith many paragraphsEOFputs long_string.empty?puts long_string.include? "many"puts french_string + long_string# concatenatehash = { key1: "val1", key2: "val2" }string = ""str2 = ""hash.each{|k,v| string << k.to_s << " is " << v << "\n" }hash.each{|k,v| str2 << "#{k}" << " is " << "#{v}" << "\n"}puts stringputs str2# joindata = [‘1‘, ‘2‘, ‘3‘]s = ‘‘data.each { |x| s << x << ‘ and a ‘}puts s # => "1 and a 2 and a 3 and a "puts data.join(‘ and a ‘)# numbernumber = 5puts "The number is #{number}." # => "The number is 5."puts "The number is #{5}." # => "The number is 5."puts "The number after #{number} is #{number.next}."# => "The number after 5 is 6."puts "The number prior to #{number} is #{number-1}."# => "The number prior to 5 is 4."puts "We‘re ##{number}!" # => "We‘re #5!"
puts "I‘ve set x to #{x = 5; x += 1}."# Escapingputs "\#{foo}"puts ‘#{foo}‘# puts "#{foo}" # error because no variable of foo defined.
template = ‘Oceania has always been at war with %s.‘puts template % ‘Eurasia‘ # => "Oceania has always been at war with Eurasia."puts ‘To 2 decimal places: %.4f‘ % Math::PIputs ‘Zero-padded: %.3d‘ % Math::PI

JSP, ASP type

require ‘erb‘template = ERB.new %q{Chunky <%= food %>!}food = "bacon"puts template.result(binding) # => "Chunky bacon!"food = "peanut butter"puts template.result(binding) # => "Chunky peanut butter!"puts template.result

 

ruby 學習 -- string --1

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.