C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Tip: The string returned by the Trim Function does not contain the leading spaces or trailing space.
Next: To demonstrate, we print out the resulting value with square brackets denoting its first and last character positions.
VB.NET program that uses Trim function
Module Module1
    Sub Main()
        ' Input string.
        Dim value As String = "  This is an example string. "
        ' Invoke Trim function.
        value = value.Trim()
        ' Write output.
        Console.Write("[")
        Console.Write(value)
        Console.WriteLine("]")
    End Sub
End Module
Output
[This is an example string.]
VB.NET program that uses Trim on file lines
Imports System.IO
Module Module1
    Sub Main()
        ' Read in the lines of a file.
        For Each line As String In File.ReadAllLines("data.txt")
            ' The existing line.
            Console.WriteLine("[{0}]", line)
            ' Trimmed line.
            Dim trimmed As String = line.Trim()
            Console.WriteLine("[{0}]", trimmed)
        Next
    End Sub
End Module
Output
[  Something]
[Something]
[Example    ]
[Example]
[  Another]
[Another]
Tip: This ensures that whitespace, which is typically not meaningful in this context, will not disrupt accurate lookups.
Dictionary