Skip to content

Instantly share code, notes, and snippets.

@ajokela
Created October 4, 2012 13:39
Show Gist options
  • Save ajokela/3833577 to your computer and use it in GitHub Desktop.
Save ajokela/3833577 to your computer and use it in GitHub Desktop.
string to acronym
acronym = ''
bytes = [] # Byte array
long_string = ' ' + long_string # so the first letter, if capital, is included
long_string.each_byte {|byte| bytes.push(byte)} # Build array of bytes
bytes.each_with_index do |byte, index|
if byte > 64 and byte < 96 # This is the range for ASCII capital letters, your encoding may vary
# Capital letter
if bytes[index-1] == 32 # We check behind to see if the
#letter is preceded by a space. Again, encoding may vary. 32 is ASCII space.
acronym = acronym + long_string[index,1]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment