这是我的功能(更新):
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
我修复了它没有返回maxLength
字符的问题,因为它没有考虑到省略号。
在我看来,这太复杂了;任何建议、评论和关注都非常受欢迎。