Is there a LotusScript or Formula Language function that takes a string value and returns the same string with all leading, trailing, andembedded white spaces removed? I want to determine the number of non-blank characters in a string. Len() counts all characters, including blanks. Fulltrim() removes duplicate spaces in the middle of a string, but not single spaces.
Subject: Remove spaces from string?
x = ReplaceSubstring(y, " ", “”)
where:
Function ReplaceSubstring (fullstring As String, oldstring As String, newString As String) As String
Dim lenOldString As Integer, Position As Integer
lenOldString = Len(oldString)
Position = Instr(fullstring, oldstring)
Do While position > 0 And oldString <> ""
fullstring = Left (fullstring, position-1) & newstring & Mid(fullstring, position + lenoldstring)
Position = Instr(position + Len(newstring) , fullstring, oldstring)
Loop
ReplaceSubstring = Fullstring
End Function
Subject: RE: Remove spaces from string?
Ah, yes. I never use it, since the rules can really do weird things to a string if you use multi-value arrays.
Subject: Remove spaces from string?
unspaced$ = Join(Split(StringName," “),”")
Subject: Remove spaces from string?
You could use something like this single liner…
@ReplaceSubstring(StringTobeProcessed; " "; “”)
and of-course could use “Evaluate” function in script if you wanted to do it in script. This would be the easiest but writing a simple script function that iterates throug all characters in the string and replaces blanks with nulls should not be hard either…
Subject: RE: Remove spaces from string?
Lotusscript version of @ReplaceSubString which I got off of the Notes 4/5 forum:
Function replaceSubString(_
st As String, _
f As String, _
t As String) As String
'/**
'* Function replaceSubString
'* The following function will search the
'* passed string “st” for the string “f”. If
'* found all instances will be replaced with
'* the string “t”.
'*
'* @param st the string to be parsed
'* @param f the string that we are looking for
'* @param t the string that we would like “f”
'* to be changed to
'*
'* @return a new string with all instances “f”
'* replaced by “t”
'*
'*/
Dim returnValue As String
Dim temp As String
temp = st
Dim i As Integer
i = Instr(temp, f)
While (i > 0)
returnValue = _
returnValue + _
Left(temp, i -1) + t
temp = Mid(temp, i + Len(f))
i = Instr(temp, f)
Wend
returnValue = returnValue + temp
replaceSubString = returnValue
End Function
Subject: I would make a change to that code…
Dim returnValue As String Dim temp As String
temp = st
Dim i As Integer
If Instr(t, f) Then
replaceSubString = temp
Exit Function
End If
Also given the results from the people who used “split” as a function, I would think of calling it something else like myReplaceSubString()
Subject: *@ReplaceSubstring(string; " "; “”) perhaps
Subject: “native” Replace function . . .
There is a “native” Replace function in LS. For example:
Dim strSpacedTxt As String
Dim strUnspacedTxt As String
strSpacedTxt$ = “This is my T E X T string!”
strUnspacedTxt$ = Replace(strSpacedTxt$, " ", “”)
Print "With spaces: " & strSpacedTxt$
Print "Without spaces: " & strUnspacedTxt$
Output:
With spaces: This is my T E X T string!
Without spaces: ThisismyTEXTstring!
Just my $0.02
dgg
Subject: Remove spaces from string?
Thanks for all your suggestions. The Replace()function is just what I was looking for.