VB code and Sql Server Ansi Padding

Discussion in 'ASP .Net' started by =?Utf-8?B?U2FuZHk=?=, May 11, 2005.

  1. 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
     
    =?Utf-8?B?U2FuZHk=?=, May 11, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?U2FuZHk=?=

    David Young Guest

    Can't you just use String.Trim()

    Dim output as String = input.Trim()


    "Sandy" <> wrote in message
    news:...
    > 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
     
    David Young, May 11, 2005
    #2
    1. Advertising

  3. 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" <> wrote in message
    > news:...
    > > 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

    >
    >
    >
     
    =?Utf-8?B?U2FuZHk=?=, May 11, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daves
    Replies:
    1
    Views:
    384
  2. Paul Connolly

    pre ANSI code and writable-strings?

    Paul Connolly, Oct 12, 2006, in forum: C Programming
    Replies:
    7
    Views:
    368
    Gordon Burditt
    Oct 17, 2006
  3. Replies:
    1
    Views:
    494
  4. Replies:
    11
    Views:
    1,084
    Keith Thompson
    Apr 28, 2008
  5. Frank Iannarilli

    pre-ansi to ansi c++ conversion?

    Frank Iannarilli, Jul 21, 2009, in forum: C++
    Replies:
    2
    Views:
    417
Loading...

Share This Page