Created
October 4, 2012 13:39
-
-
Save ajokela/3833577 to your computer and use it in GitHub Desktop.
string to acronym
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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