The trick is that abbreviation only makes sense when it shortens the word. A word of length abbreviates to at most 4 characters (like "a18b" where 18 is two digits). So if , the original word is short enough.
Keep it as-is. If , abbreviate it. The middle count is because you keep the first and last characters. String indexing gives you easy access to any character. The first character is at index 0, the last at index .
The middle count is just arithmetic: total length minus the two characters you keep.