Skip to content

Instantly share code, notes, and snippets.

@amorphid
Created April 10, 2013 17:34
Show Gist options
  • Select an option

  • Save amorphid/5356720 to your computer and use it in GitHub Desktop.

Select an option

Save amorphid/5356720 to your computer and use it in GitHub Desktop.
Basic way to calculate length of a string
# breaks if string includes a 0
def string_length(a)
string = a + "0"
length = 0
while string[length] != "0"
length += 1
end
puts "Your statement is #{length} characters long"
end
string_length("I am a meat popsicle.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment