String.Contains (), compare, clone in VB.net
By: Issac
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"
Archived Comments
1. Love the website-- extremely individual friendly and lots to see!
[url=http:/
View Tutorial By: http://www.essentielbio.us at 2017-06-15 01:34:15
2. Thank you for sharing this great site.
[url=http://heqgateway.com/viewtopic.php?t=167
View Tutorial By: meilleur massage lyon at 2017-06-14 21:35:32
3. Amazing web page you have in here.
[url=http://cheakheng.com/?option=com_k2&view=
View Tutorial By: https://www.votretherapie.us at 2017-06-14 18:48:14
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
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
Exception Filtering in the Catch Block in VB.net
Using Multiple Catch Statements in VB.net
Throwing an Exception in VB.net
Throwing a Custom Exception in VB.net
Changes in Controls from VB6 to VB.net
Unstructured Exception Handling in VB.net