Results 1 to 6 of 6

Thread: Is there a command to remove Null Chars from the end of a string?

  1. #1

    Thread Starter
    Hyperactive Member Filter300's Avatar
    Join Date
    Aug 2001
    Posts
    413

    Unhappy Is there a command to remove Null Chars from the end of a string?

    I need somthning to remove the null characters from the end of my string kinda like the r trim for spaces. thanks

  2. #2
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    VB Code:
    1. Public Function StripNulls(OriginalStr As String) As String
    2.     If (InStr(OriginalStr, Chr(0)) > 0) Then
    3.         OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
    4.     End If
    5.     StripNulls = OriginalStr
    6. End Function

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    This should do the trick I believe

    Code:
    Do Until Asc(Right(strName, 1)) <> 0
        strName = Left(strName, Len(strName) - 1)
        DoEvents
    Loop
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4
    Addicted Member Merlin's Avatar
    Join Date
    Dec 2000
    Location
    Eau Claire, WI
    Posts
    233
    You could check for the null characters at the end then do a

    VB Code:
    1. Left(variable, Len(variable) - Number Of Null Characters)

    Something like that anyway...
    poooof

    Wizard Since 1997
    SQL Server 7.0:2K, Oracle, VB 6.0 EE, VBScript, C/C++, COBOL, RPG ILE, HTML, XML, Perl

  5. #5
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Code:
    Temp = Replace(variable, Chr(0), "")
    Last edited by ExcalibursZone; Aug 28th, 2001 at 11:56 AM.
    -Excalibur

  6. #6
    Addicted Member
    Join Date
    Mar 2001
    Posts
    130
    Hey,

    Nice solution!



    -mort

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width