String.Contains (), compare, clone in VB.net

By: Issac Emailed: 1698 times Printed: 2201 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

Contains method is an important string class method which checks whether specified parameter string exists in the string or not

System.String.Contains(String str) As Boolean 

Parameters: 
String str – the input String which we gonna search

Returns: 
Boolean - Yes/No
If the str is in the String then it returns true
If the str is not in the String it returns False

For ex: "I am what I am".Contains ("I") returns True
"This is a Test”.Contains (“me”) 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 = "for java articles java-samples.com"
If str.Contains("samples") = True Then
MsgBox("The string Contains() ‘samples’ ")
Else
MsgBox("The String does not contains() ’samples’ ")
End If
End Sub
End Class

When you run the program you will get the MessageBox with message "The string Contains() 'samples' "

The VB.NET String Compare function is used to compare two String Objects.
System.String.Compare(String str1,String str2, Boolean ) As Integer 
It returns an Integer indication which specifies the logical relationship between the two strings

Parameters: 
• String str1 
• String str2 
Boolean True/False Indication is to check whether the String is case sensitive or not

Returns: 
Integer : returns less than zero, zero or greater than zero.
Less than zero : str1 is less than str2
zero : str1 is equal to str2
Greater than zero : str1 is grater than 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 = "issac"
str2 = "ISSAC"

Dim result As Integer

result = String.Compare(str1, str2)
MsgBox(result)

result = String.Compare(str1, str2, True)
MsgBox(result)
End Sub
End Class

When you run this code first u get -1 in message box specifying string 2 is greater and then 0 specifying the strings are equal.

The VB.NET String Clone () method returns a reference to this instance of String.
Public Function Clone() As Object 

Returns: 
Object : Return the instance of the String
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String = "Clone() Test"
Dim clonedString As String
clonedString = str.Clone()
MsgBox(clonedString)
End Sub
End Class


When you run this program you ill get the same content of the first string "Clone() Test"


VB.net Home | All VB.net Tutorials | Latest VB.net Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Issac
Save/Write/Read image file from/to a database using Java program
How to modify the objects using java classes
Java program for Cloning
Java program for changeable wrapper class
A tutorial on Chat Server and Chat Client in VB.net
Chat Server in VB.net
Chat client in VB.net
How to open and read an XML file in VB.net
How to create an XML file in VB.net
XML and VB.net
How to create an XML file in VB.NET using Dataset
Multi Threaded Client Socket Programming in VB.net
Multi Threaded Server Socket Programming in VB.net
Multi threaded Socket Programming in VB.net
Client Socket Program sample in VB.net

More Tutorials in VB.net
Scope in VB.net
Unstructured Exception Handling in VB.net
Structured Exception Handling in VB.net
Creating Sub Procedures in VB.net
Creating Functions in VB.net
Passing a Variable Number of Arguments to Procedures in VB.net
Specifying Optional Arguments with default values in Procedures in VB.net
Preserving a Variable's Values between Procedure Calls in VB.net
Procedure Delegates in VB.net
Properties in VB.net
Understanding Scope in VB.net
Using Resume Next and Resume Line in VB.net
Using On Error GoTo 0 in VB.net
Getting an Exception's Number and Description in VB.net
Raising an Exception Intentionally in VB.net

More Latest News
Most Viewed Articles (in VB.net )
File Extensions Used in VB .NET
Your first VB.NET Crystal Reports - A step by step guide
Converting between Data Types in VB.net
Arrays and Dynamic Arrays in VB.net
For Loop in VB.net
How to export from DataGridView to excel using VB.net
How to create an XML file in VB.NET using Dataset
A tutorial on Chat Server and Chat Client in VB.net
Passing a Variable Number of Arguments to Procedures in VB.net
Preserving a Variable's Values between Procedure Calls in VB.net
“Using If with And” and Comparing two integers using If
Debug and Release Versions in .NET
Using Select Case in VB.net
Do Loop in VB.net
For Each…Next Loop in VB.net
Most Emailed Articles (in VB.net)
How to export from database to excel using VB.net
What is .NET Framework and the Common Language Runtime?
Create an Excel 2007 file in VB.NET 2005
Insert Pictures in Excel 2007 from VB.NET 2005
Socket Programming in VB.net
Chat Server in VB.net
Using the ServiceBase Class in VB.net
Changes in Controls from VB6 to VB.net
While Loop in VB.net
String Insert, index off & format in VB.net
Substring in Vb.Net String Class
String Split function in VB.net
Vb.net text reader
Using Excel 2007 Chart VB.net Picture Box
Using Excel 2007 DataBar in VB.net