Skip to content

Latest commit

 

History

History
49 lines (34 loc) · 424 Bytes

strings.md

File metadata and controls

49 lines (34 loc) · 424 Bytes

Strings

String match

a="Hello"
if a.match /[a-zA-Z]/
 puts "It's a match!"
end

a="Hello"
if a=~/[a-zA-Z]/
 puts "It's a match!"      #Better
end

String repetition

6.times do
 print "Hello"
end

print "Hello"*6 #Better

Single char

puts "A"

puts ?A #Better

Char ascii

puts 70.chr

putc 70 #Better

\n shortcut

a=gets.split "\n"

a=gets.split $/ #Better