Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > VB code and Sql Server Ansi Padding

Reply
Thread Tools

VB code and Sql Server Ansi Padding

 
 
=?Utf-8?B?U2FuZHk=?=
Guest
Posts: n/a
 
      05-11-2005
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!
--
Sandy
 
Reply With Quote
 
 
 
 
David Young
Guest
Posts: n/a
 
      05-11-2005
Can't you just use String.Trim()

Dim output as String = input.Trim()


"Sandy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!
> --
> Sandy



 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2FuZHk=?=
Guest
Posts: n/a
 
      05-11-2005
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

"David Young" wrote:

> Can't you just use String.Trim()
>
> Dim output as String = input.Trim()
>
>
> "Sandy" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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!
> > --
> > Sandy

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pre-ansi to ansi c++ conversion? Frank Iannarilli C++ 2 07-21-2009 11:05 PM
Help. Getting a An error has occurred while establishing a connectionto the server. When connecting to SQL Server 2005, this failure may be causedby the fact that under the default settings SQL Server does not allow remote aboutjav.com@gmail.com ASP .Net 0 05-03-2008 12:43 PM
Are there statistics packages in ANSI C and/or ANSI C++? lbrtchx@gmail.com C Programming 11 04-28-2008 03:00 AM
Are there statistics packages in ANSI C and/or ANSI C++? lbrtchx@gmail.com C++ 1 04-24-2008 06:44 PM
sql server express vs sql server 2000 code Daves ASP .Net 1 06-13-2005 12:24 PM



Advertisments