Skip to content

Instantly share code, notes, and snippets.

@isokcevic
Created November 24, 2021 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isokcevic/ed265973945ecd0caad00d3414aaa04f to your computer and use it in GitHub Desktop.
Save isokcevic/ed265973945ecd0caad00d3414aaa04f to your computer and use it in GitHub Desktop.
name = "A B C D"
puts
puts "Different name modifications"
puts "original #{name}"
puts "sub #{name.sub(' ', '')}"
puts "gsub #{name.gsub(' ', '')}"
puts "delete #{name.delete(' ')}"
puts
puts "Different length calculations"
puts "original #{name.length}"
puts "minus one #{name.length - 1}"
puts "sub #{name.sub(' ', '').length}"
puts "gsub #{name.gsub(' ', '').length}"
puts "delete #{name.delete(' ').length}"
puts "minus count #{name.length - name.count(' ')}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment