G
Guest
Hello -
I didn't know what to call this problem in the Subject, but here goes:
I have a wonderful Function (below) which I snagged off the internet that
does exactly what it's supposed to do - take anything longer than the
designated amount of characters, truncate it and add "..." at the end.
It was not working correctly for me - it added "..." to every text string,
even if it was a five-letter word. I figured out that the problem is when I
created my database, I had Ansi Padding on; thus the vb code thinks
everything is the same length. Is there a way to handle this on the Visual
Basic side of things or do I have to remove the padding from the column in
Sql Server? I'd rather not mess with the database if there is some
work-around.
Public Function Truncate(ByVal input as String, ByVal characterLimit as
Integer) As String
Dim output as String = input
If output.Length > characterLimit Then
output = output.Substring(0,characterLimit)
If input.Substring(output.Length,1) <> " " Then
Dim LastSpace as Integer = output.LastIndexOf(" ")
If LastSpace <> -1 Then
output = output.Substring(0,LastSpace)
End If
End If
output = output + "..."
End If
return output
End Function
Any help will be greatly appreciated!
I didn't know what to call this problem in the Subject, but here goes:
I have a wonderful Function (below) which I snagged off the internet that
does exactly what it's supposed to do - take anything longer than the
designated amount of characters, truncate it and add "..." at the end.
It was not working correctly for me - it added "..." to every text string,
even if it was a five-letter word. I figured out that the problem is when I
created my database, I had Ansi Padding on; thus the vb code thinks
everything is the same length. Is there a way to handle this on the Visual
Basic side of things or do I have to remove the padding from the column in
Sql Server? I'd rather not mess with the database if there is some
work-around.
Public Function Truncate(ByVal input as String, ByVal characterLimit as
Integer) As String
Dim output as String = input
If output.Length > characterLimit Then
output = output.Substring(0,characterLimit)
If input.Substring(output.Length,1) <> " " Then
Dim LastSpace as Integer = output.LastIndexOf(" ")
If LastSpace <> -1 Then
output = output.Substring(0,LastSpace)
End If
End If
output = output + "..."
End If
return output
End Function
Any help will be greatly appreciated!