VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Squeeze

by John Bambrick (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

Removes extra spaces from given string. eg. Squeeze("^^too^^many^^^spaces^^")returns "too^many^spaces". NB.Read a carat ^ as a single space above. vbcoders.com mangles multiple spaces in submitted text.

Inputs
A string, strText.
Assumes
Doesn't strip tabs, CRLFs or any characters from text EXCEPT char 32.
Code Returns
A string = strText without spaces and the beginning or end or more than 1 consecutive space within.
Side Effects
None.

Rate Squeeze

Public Function Squeeze (ByVal strText As String) As String
 Dim intPos As Integer
 
 intPos = InStr(1, strText, Chr(32) & Chr(32))
 If intPos = 0 Then
 Squeeze = Trim(strText)
 Else
 strText = _
 Left(strText, intPos - 1) & _
 Mid(strText, intPos + 1)
 Squeeze = Squeeze(strText)
 End If
End Function

Download this snippet    Add to My Saved Code

Squeeze Comments

No comments have been posted about Squeeze. Why not be the first to post a comment about Squeeze.

Post your comment

Subject:
Message:
0/1000 characters