VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Removes excess spaces left over at the end of a string when using random access files. Since random

by Chad Tiffin (1 Submission)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 25th February 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Removes excess spaces left over at the end of a string when using random access files. Since random file fields are of a set length, if the

API Declarations



Drop me a line if you found the function usefull!

Rate Removes excess spaces left over at the end of a string when using random access files. Since random



    'This function will remove the spaces from the end
    'of a string read from a random access file by reading from
    'the right to left and asking each time if the character
    'it read is a space.  As soon as it is not equal to a
    'space, it will re-write the string using only the
    'characters from the left up to the point where it found
    'the first non-space character.
    
    Dim char As String
    RemoveSpaces = ""
    For a = 1 To Len(Str)
        char = Mid(Right(Str, a), 1, 1) 'Reads a single character starting from the right and working to the left
        If char = " " Then
        Else
            RemoveSpaces = Mid(Str, 1, Len(Str) - a + 1) 'The +1 is so the last non-space character in the string is not erased
            Exit For
        End If
    Next a
End Function

'EXAMPLE OF USE
'dim Name as String
'Name = "Bill          "
'Name = RemoveSpaces(Name)

Download this snippet    Add to My Saved Code

Removes excess spaces left over at the end of a string when using random access files. Since random Comments

No comments have been posted about Removes excess spaces left over at the end of a string when using random access files. Since random. Why not be the first to post a comment about Removes excess spaces left over at the end of a string when using random access files. Since random.

Post your comment

Subject:
Message:
0/1000 characters