VB code and Sql Server Ansi Padding

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!
 
G

Guest

David --

Thank you so much for responding! For some reason, I was thinking this was
going to be some great big problem -- don't ask me why. Thanks for saving me
time!!

Sandy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top