stringvb.net

Is there a difference between the Visual Basic Strings.Trim(String) method and the .NET String.Trim method?


Is there a difference between using the Visual Basic (VB.NET) Strings.Trim(String) method:

Dim myString As String = "    myString    "
myString = Trim(myString)

and the .NET String.Trim method:

Dim myString As String = "    myString    "
myString = myString.Trim()

Solution

  • Yes, the results of these two methods can be different. The first Strings.Trim(String) method -- Trim(myString) -- trims only spaces off the leading and trailing parts of the string, not tabs or other whitespace characters. The second String.Trim method -- myString.Trim() -- trims all whitespace (including tabs, carriage returns, linefeeds ... any character for which IsWhiteSpace(char) returns true) off the leading and trailing parts of the string.