Domino Code Fragment

Code Name*
Function to remove excess spaces from a string
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.147.42.168
Description*
Remove all excess spaces from the string s
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Deflate Function

Function Deflate( sInput As String ) As String

Removes all excess spaces from a string.

Function Syntax

Deflate( sInput )

Formal Parameters

sInput

A string of AlphaNumeric Characters.

Return value

The Deflate function's return value is a string. This string will contain the original string minus excess spaces or excess NULL characters.

Function

Function Deflate(sInput As String) As String
'--Remove all excess spaces from the string sInput
Dim sChange As String
sChange = ""
'-- Next line gets rid of the leading and trailing spaces but not spaces from the middle
sInput = Trim(sInput)
'-- Loop thru each character in the string copying the characters to a new string var.
Do While sInput <> ""
If Left(sInput, 1) <> " " Then
'-- The character is not a space, put it in sChange
sChange = sChange + Left(sInput, 1)
'-- Take the character out of the input string

'-- Mid function used this way will return the string from the 2nd position to the end
sInput = Mid(sInput, 2)
Else
'-- It is a space, so keep just one space character
sChange = sChange + " "
'-- Eat all the spaces
'-- and adjust the sinput string so a non-space character is next to process
Do While Left(sInput, 1) = " "
sInput = Mid(sInput, 2)
Loop
End If
Loop

'-- Assign the result to our function to return the value
Deflate = sChange
End Function

Usage

The valid value for the sInput is a string of alphanumeric charaters.

Example

This example will take the string "This is a test of the deflate function!" and remove excess NULL characters. The string will be displayed to the screen before and after the call to Deflate function. The return is assigned to a variable of type string.

Sub Click(Source As Button)
Dim sSentence As String
sSentence = "This is a test of the deflate function!"
Messagebox sSentence,
MB_ICONINFORMATION, "See my string"
sSentence = deflate(sSentence)
Messagebox sSentence,
MB_ICONINFORMATION, "See my string now!"
End Sub