VB6 has a Trim() function, but only removes spaces.
To remove characters from both ends, you need to check each end, in turn, delete the character until you get something else:
Function TrimChar(ByVal Text As String, ByVal Characters As String) As String 'Trim the right Do While Right(Text, 1) Like "[" & Characters & "]" Text = Left(Text, Len(Text) - 1) Loop 'Trim the left Do While Left(Text, 1) Like "[" & Characters & "]" Text = Mid(Text, 2) Loop 'Return the result TrimChar = Text End Function
Result:
?TrimChar("........I.wanna.delete.only.the.dots.outside.of.this.text...............", ".") I.wanna.delete.only.the.dots.outside.of.this.text
This is far from optimized, but you can expand it to just work out the end positions, and then make one call to Mid() .
source share