RTrim Function in VB.NET

How to use the RTrim Function in VB.NET?

Explanation

RTrim Function

Rtrim(), Right Trim String Function in Visual Basic.net 2008 returns a copy of a string by removing the trailing whitespaces.
Syntax:

Function RTrim(ByVal Str As String) As String

In the above syntax, the Str is the string from which the trailing white spaces are removed.
Example:

Module Module1
Sub Main()
Dim Str As String = "
HII
"
Dim Pre As String = "Prefix"
Dim Sfx As String = "Suffix"
Console.WriteLine("String after removing
trailing spaces:: " & Pre + RTrim(Str) + Sfx)
Console.ReadLine()
End Sub
End Module
Result:

String after removing trailing spaces:: Prefix HIISuffix

In the above example, three spaces are included in the string 'HII' to its prefix, sufix. Using the RTrim Right trim string function only, the trailing spaces are removed and concatenated with string to find it.

Visual Basic Tutorial


Ask Questions

Ask Question