TRIM

TRIM(string)

Returns the text string without leading and trailing spaces (Variant / String).


stringThe text string (String).

REMARKS
* If "string" = "" (zero length string), then a zero length string is returned.
* If "string" is vbNullString, then a zero length string is returned.
* You can use the LTRIM function to return a text string without leading spaces.
* You can use the RTRIM function to return the text string without trailing spaces.
* You can use the TRIM$ function to return a String data type instead of a Variant data type.
* The equivalent Excel function is Application.WorksheetFunction.TRIM
* Unlike the Excel function this function WILL NOT remove any extra spaces between words.
* The equivalent .NET function is [[Microsoft.VisualBasic.Strings.Trim]]
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print Trim("   some text   ")  '= "some text"  
Debug.Print Trim(" hello ") '= "hello"
Debug.Print Trim(" some text ") '= "some text"
Debug.Print Trim("12 3 4") '= "12 3 4"
Debug.Print Trim(1234) '= "1234"

sResult = Trim("")
Debug.Print "'" & sResult & "'" '= "''"

sResult = Trim(vbNullString)
Debug.Print "'" & sResult & "'" '= "''"

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top