Here is my function (updated):
Public Shared Function shortenUrl(ByVal URL As String) As String
Return shortenUrl(URL, 32)
End Function
Public Shared Function shortenUrl(ByVal URL As String, ByVal maxLength As Integer) As String
If URL.Length > maxLength Then
String.Format("{0}...{1}", URL.Substring(0, (maxLength / 2)), URL.Substring(URL.Length - ((maxLength / 2) - 3)))
Else
Return URL
End If
End Function
I fixed the problem where it didn't return maxLength
chars because it didn't take into account the ellipses.
It seems to me that it is too complicated; any suggestions, comments, concerns are more than welcome.