String endswith, concat in VB.net

By: Issac  

To check the whether the given string ends with specified string we use EndsWith method in String class

System.String.EndsWith (String suffix) as Boolean 

Parameters: 
Suffix – the suffix of the given string

Returns: 
Boolean - Yes/No
If the String EndsWith the Parameter String it returns True
If the String doesnt EndsWith the Parameter String it return False

For ex : "This is a Test".EndsWith("Test") returns True
"This is a Test".EndsWith("is") returns False

Exceptions: 
System.ArgumentNullException : If the argument is null

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, 
ByVal e As System.EventArgs) Handles Button1.Click

Dim str As String
str = "GOD BLESS YOU"
If str.EndsWith("YOU") = True Then
MsgBox("The String EndsWith 'BOOKS' ")
Else
MsgBox("The String does not EndsWith 'BOOKS'")
End If

End Sub
End Class

When you execute the program you will get a message box like "The String EndsWith 'YOU' "
Concat in VB.NET String Class using for concat two specified String Object
System.String.Concat (ByVal str1 As String, ByVal str2 As String) As String 
String Concat method returns a new String

Parameters: 
• String str1 
• String str2 

Returns: 
String: A new String retrun with str1 Concat with str2

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

Dim str1 As String
Dim str2 As String

str1 = "Concat() "
str2 = "Test"
MsgBox(String.Concat(str1, str2))

End Sub
End Class 

When you run this source code you will get "Concat () Test " in message box.




Archived Comments


Most Viewed Articles (in VB.net )

Latest Articles (in VB.net)

Comment on this tutorial